1 // P0018R3 - C++17 lambda capture of *this
2 // { dg-do run { target c++11 } }
5 extern "C" void abort ();
10 A (const A &x) : a (x.a), z (1) {}
13 auto b = [this] { return &a; };
14 auto c = [*this] { return &a; }; // { dg-warning "'*this' capture only available with" "" { target c++14_down } }
15 auto d = [=] { return &a; };
16 auto e = [&] { return &a; };
17 if (b () != &a) abort ();
18 if (*b () != 4) abort ();
20 if (c () == &a) abort ();
21 if (c () != f) abort ();
22 if (*c () != 4) abort ();
23 if (d () != &a) abort ();
24 if (e () != &a) abort ();
25 auto g = [this] { return a + z; };
26 auto h = [*this] { return a + z; }; // { dg-warning "'*this' capture only available with" "" { target c++14_down } }
27 auto i = [=] { return a + z; };
28 auto j = [&] { return a + z; };
29 if (g () != 4 || h () != 5 || i () != 4 || j () != 4) abort ();
36 B () : a (N), z (0) {}
37 B (const B &x) : a (x.a), z (1) {}
40 auto b = [this] { return &a; };
41 auto c = [*this] { return &a; }; // { dg-warning "'*this' capture only available with" "" { target c++14_down } }
42 auto d = [=] { return &a; };
43 auto e = [&] { return &a; };
44 if (b () != &a) abort ();
45 if (*b () != 9) abort ();
47 if (c () == &a) abort ();
48 if (c () != f) abort ();
49 if (*c () != 9) abort ();
50 if (d () != &a) abort ();
51 if (e () != &a) abort ();
52 auto g = [this] { return a + z; };
53 auto h = [*this] { return a + z; }; // { dg-warning "'*this' capture only available with" "" { target c++14_down } }
54 auto i = [=] { return a + z; };
55 auto j = [&] { return a + z; };
56 if (g () != 9 || h () != 10 || i () != 9 || j () != 9) abort ();