1 // P0806R2
2 // { dg-do compile { target c++17 } }
3 // { dg-options "" }
4 
5 struct X {
6   int x;
fooX7   void foo (int n) {
8     auto a1 = [=] { x = n; }; // { dg-bogus "implicit capture" "" { target c++17_down } }
9 			      // { dg-warning "implicit capture of 'this' via '\\\[=\\\]' is deprecated" "" { target c++2a } .-1 }
10 			      // { dg-message "add explicit 'this' or '\\\*this' capture" "" { target c++2a } .-2 }
11     auto a2 = [=, this] { x = n; };
12     // { dg-warning "explicit by-copy capture" "" { target c++17_down } .-1 }
13     auto a3 = [=, *this]() mutable { x = n; };
14     auto a4 = [&] { x = n; };
15     auto a5 = [&, this] { x = n; };
16     auto a6 = [&, *this]() mutable { x = n; };
17 
18     auto a7 = [=] { // { dg-bogus "implicit capture" "" { target c++17_down } }
19 		    // { dg-warning "implicit capture of 'this' via '\\\[=\\\]' is deprecated" "" { target c++2a } .-1 }
20 		    // { dg-message "add explicit 'this' or '\\\*this' capture" "" { target c++2a } .-2 }
21       auto a = [=] { // { dg-bogus "implicit capture" "" { target c++17_down } }
22 		     // { dg-warning "implicit capture of 'this' via '\\\[=\\\]' is deprecated" "" { target c++2a } .-1 }
23 		     // { dg-message "add explicit 'this' or '\\\*this' capture" "" { target c++2a } .-2 }
24 	 auto a2 = [=] { x = n; }; // { dg-bogus "implicit capture" "" { target c++17_down } }
25 				   // { dg-warning "implicit capture of 'this' via '\\\[=\\\]' is deprecated" "" { target c++2a } .-1 }
26 				   // { dg-message "add explicit 'this' or '\\\*this' capture" "" { target c++2a } .-2 }
27       };
28     };
29 
30     auto a8 = [=, this] {
31     // { dg-warning "explicit by-copy capture" "" { target c++17_down } .-1 }
32       auto a = [=, this] {
33     // { dg-warning "explicit by-copy capture" "" { target c++17_down } .-1 }
34 	 auto a2 = [=, this] { x = n; };
35     // { dg-warning "explicit by-copy capture" "" { target c++17_down } .-1 }
36       };
37     };
38 
39     auto a9 = [=, *this]() mutable {
40       auto a = [=, *this]() mutable {
41 	 auto a2 = [=, *this]() mutable { x = n; };
42       };
43     };
44 
45     auto a10 = [&] {
46       auto a = [&] {
47 	 auto a2 = [&] { x = n; };
48       };
49     };
50 
51     auto a11 = [&, this] {
52       auto a = [&, this] {
53 	 auto a2 = [&, this] { x = n; };
54       };
55     };
56 
57     auto a12 = [&, *this]() mutable {
58       auto a = [&, *this]() mutable {
59 	 auto a2 = [&, *this]() mutable { x = n; };
60       };
61     };
62   }
63 };
64