annotate gcc/testsuite/g++.dg/cpp1z/lambda-this1.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // P0018R3 - C++17 lambda capture of *this
kono
parents:
diff changeset
2 // { dg-do compile { target c++11 } }
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 struct A {
kono
parents:
diff changeset
5 int a;
kono
parents:
diff changeset
6 void foo () {
kono
parents:
diff changeset
7 int v = 4;
kono
parents:
diff changeset
8 auto b = [*this, this] {}; // { dg-error "already captured 'this'" }
kono
parents:
diff changeset
9 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
kono
parents:
diff changeset
10 auto c = [this, *this] {}; // { dg-error "already captured 'this'" }
kono
parents:
diff changeset
11 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
kono
parents:
diff changeset
12 auto d = [this] { return a; };
kono
parents:
diff changeset
13 auto e = [*this] { return a; }; // { dg-error "'*this' capture only available with" "" { target c++14_down } }
kono
parents:
diff changeset
14 auto f = [this] { a++; };
kono
parents:
diff changeset
15 auto g = [*this] { a++; }; // { dg-error "in read-only object" }
kono
parents:
diff changeset
16 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
kono
parents:
diff changeset
17 auto h = [*this] () mutable { a++; };// { dg-error "'*this' capture only available with" "" { target c++14_down } }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
18 auto i = [=] { return a; }; // { dg-warning "implicit capture" "" { target c++2a } }
111
kono
parents:
diff changeset
19 auto j = [&] { return a; };
kono
parents:
diff changeset
20 // P0409R2 - C++2A lambda capture [=, this]
kono
parents:
diff changeset
21 auto k = [=, this] { return a; };// { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" "" { target c++17_down } }
kono
parents:
diff changeset
22 auto l = [&, this] { return a; };
kono
parents:
diff changeset
23 auto m = [=, *this] { return a; };// { dg-error "'*this' capture only available with" "" { target c++14_down } }
kono
parents:
diff changeset
24 auto n = [&, *this] { return a; };// { dg-error "'*this' capture only available with" "" { target c++14_down } }
kono
parents:
diff changeset
25 auto o = [*this, &v] { return a + v; };// { dg-error "'*this' capture only available with" "" { target c++14_down } }
kono
parents:
diff changeset
26 auto p = [*this] { this = 0; }; // { dg-error "lvalue required as left operand of assignment" }
kono
parents:
diff changeset
27 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
kono
parents:
diff changeset
28 auto q = [=, this, *this] { return a; };// { dg-error "already captured 'this'" }
kono
parents:
diff changeset
29 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
kono
parents:
diff changeset
30 // { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" "" { target c++17_down } .-2 }
kono
parents:
diff changeset
31 auto r = [=, this, this] { return a; };// { dg-error "already captured 'this'" }
kono
parents:
diff changeset
32 // { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" "" { target c++17_down } .-1 }
kono
parents:
diff changeset
33 auto s = [=, *this, this] { return a; };// { dg-error "already captured 'this'" }
kono
parents:
diff changeset
34 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
kono
parents:
diff changeset
35 // { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" "" { target c++17_down } .-2 }
kono
parents:
diff changeset
36 auto t = [=, *this, *this] { return a; };// { dg-error "already captured 'this'" }
kono
parents:
diff changeset
37 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
kono
parents:
diff changeset
38 auto u = [&, this, *this] { return a; };// { dg-error "already captured 'this'" }
kono
parents:
diff changeset
39 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
kono
parents:
diff changeset
40 auto w = [&, this, this] { return a; };// { dg-error "already captured 'this'" }
kono
parents:
diff changeset
41 auto x = [&, *this, this] { return a; };// { dg-error "already captured 'this'" }
kono
parents:
diff changeset
42 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
kono
parents:
diff changeset
43 auto y = [&, *this, *this] { return a; };// { dg-error "already captured 'this'" }
kono
parents:
diff changeset
44 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
kono
parents:
diff changeset
45 }
kono
parents:
diff changeset
46 };
kono
parents:
diff changeset
47 struct B {
kono
parents:
diff changeset
48 double b;
kono
parents:
diff changeset
49 B () : b (.007) {}
kono
parents:
diff changeset
50 double foo () {
kono
parents:
diff changeset
51 return [this]{ return [*this] { return b; }; }()(); // { dg-error "'*this' capture only available with" "" { target c++14_down } }
kono
parents:
diff changeset
52 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
53 void bar () {
111
kono
parents:
diff changeset
54 auto c = []{ return [*this] { return b; }; }; // { dg-error "'this' was not captured for this lambda function" }
kono
parents:
diff changeset
55 } // { dg-error "invalid use of non-static data member 'B::b'" "" { target *-*-* } .-1 }
kono
parents:
diff changeset
56 }; // { dg-error "'*this' capture only available with" "" { target c++14_down } .-2 }
kono
parents:
diff changeset
57 struct C {
kono
parents:
diff changeset
58 int c;
kono
parents:
diff changeset
59 C (const C &) = delete;
kono
parents:
diff changeset
60 void bar () const;
kono
parents:
diff changeset
61 void foo () {
kono
parents:
diff changeset
62 auto d = [this] { return c; };
kono
parents:
diff changeset
63 auto e = [*this] { return c; }; // { dg-error "use of deleted function" }
kono
parents:
diff changeset
64 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
65 auto f = [=] { return c; }; // { dg-warning "implicit capture" "" { target c++2a } }
111
kono
parents:
diff changeset
66 auto g = [&] { return c; };
kono
parents:
diff changeset
67 auto h = [this] { bar (); };
kono
parents:
diff changeset
68 auto i = [*this] { bar (); }; // { dg-error "use of deleted function" }
kono
parents:
diff changeset
69 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
kono
parents:
diff changeset
70 }
kono
parents:
diff changeset
71 };
kono
parents:
diff changeset
72 struct D {
kono
parents:
diff changeset
73 int d;
kono
parents:
diff changeset
74 ~D () = delete;
kono
parents:
diff changeset
75 void bar () const;
kono
parents:
diff changeset
76 void foo () {
kono
parents:
diff changeset
77 auto e = [this] { return d; };
kono
parents:
diff changeset
78 auto f = [*this] { return d; }; // { dg-error "use of deleted function" }
kono
parents:
diff changeset
79 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
80 auto g = [=] { return d; }; // { dg-warning "implicit capture" "" { target c++2a } }
111
kono
parents:
diff changeset
81 auto h = [&] { return d; };
kono
parents:
diff changeset
82 auto i = [this] { bar (); };
kono
parents:
diff changeset
83 auto j = [*this] { bar (); }; // { dg-error "use of deleted function" }
kono
parents:
diff changeset
84 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
kono
parents:
diff changeset
85 }
kono
parents:
diff changeset
86 };