comparison 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
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
13 auto e = [*this] { return a; }; // { dg-error "'*this' capture only available with" "" { target c++14_down } } 13 auto e = [*this] { return a; }; // { dg-error "'*this' capture only available with" "" { target c++14_down } }
14 auto f = [this] { a++; }; 14 auto f = [this] { a++; };
15 auto g = [*this] { a++; }; // { dg-error "in read-only object" } 15 auto g = [*this] { a++; }; // { dg-error "in read-only object" }
16 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 } 16 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
17 auto h = [*this] () mutable { a++; };// { dg-error "'*this' capture only available with" "" { target c++14_down } } 17 auto h = [*this] () mutable { a++; };// { dg-error "'*this' capture only available with" "" { target c++14_down } }
18 auto i = [=] { return a; }; 18 auto i = [=] { return a; }; // { dg-warning "implicit capture" "" { target c++2a } }
19 auto j = [&] { return a; }; 19 auto j = [&] { return a; };
20 // P0409R2 - C++2A lambda capture [=, this] 20 // P0409R2 - C++2A lambda capture [=, this]
21 auto k = [=, this] { return a; };// { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" "" { target c++17_down } } 21 auto k = [=, this] { return a; };// { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" "" { target c++17_down } }
22 auto l = [&, this] { return a; }; 22 auto l = [&, this] { return a; };
23 auto m = [=, *this] { return a; };// { dg-error "'*this' capture only available with" "" { target c++14_down } } 23 auto m = [=, *this] { return a; };// { dg-error "'*this' capture only available with" "" { target c++14_down } }
48 double b; 48 double b;
49 B () : b (.007) {} 49 B () : b (.007) {}
50 double foo () { 50 double foo () {
51 return [this]{ return [*this] { return b; }; }()(); // { dg-error "'*this' capture only available with" "" { target c++14_down } } 51 return [this]{ return [*this] { return b; }; }()(); // { dg-error "'*this' capture only available with" "" { target c++14_down } }
52 } 52 }
53 double bar () { 53 void bar () {
54 auto c = []{ return [*this] { return b; }; }; // { dg-error "'this' was not captured for this lambda function" } 54 auto c = []{ return [*this] { return b; }; }; // { dg-error "'this' was not captured for this lambda function" }
55 } // { dg-error "invalid use of non-static data member 'B::b'" "" { target *-*-* } .-1 } 55 } // { dg-error "invalid use of non-static data member 'B::b'" "" { target *-*-* } .-1 }
56 }; // { dg-error "'*this' capture only available with" "" { target c++14_down } .-2 } 56 }; // { dg-error "'*this' capture only available with" "" { target c++14_down } .-2 }
57 struct C { 57 struct C {
58 int c; 58 int c;
60 void bar () const; 60 void bar () const;
61 void foo () { 61 void foo () {
62 auto d = [this] { return c; }; 62 auto d = [this] { return c; };
63 auto e = [*this] { return c; }; // { dg-error "use of deleted function" } 63 auto e = [*this] { return c; }; // { dg-error "use of deleted function" }
64 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 } 64 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
65 auto f = [=] { return c; }; 65 auto f = [=] { return c; }; // { dg-warning "implicit capture" "" { target c++2a } }
66 auto g = [&] { return c; }; 66 auto g = [&] { return c; };
67 auto h = [this] { bar (); }; 67 auto h = [this] { bar (); };
68 auto i = [*this] { bar (); }; // { dg-error "use of deleted function" } 68 auto i = [*this] { bar (); }; // { dg-error "use of deleted function" }
69 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 } 69 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
70 } 70 }
75 void bar () const; 75 void bar () const;
76 void foo () { 76 void foo () {
77 auto e = [this] { return d; }; 77 auto e = [this] { return d; };
78 auto f = [*this] { return d; }; // { dg-error "use of deleted function" } 78 auto f = [*this] { return d; }; // { dg-error "use of deleted function" }
79 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 } 79 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
80 auto g = [=] { return d; }; 80 auto g = [=] { return d; }; // { dg-warning "implicit capture" "" { target c++2a } }
81 auto h = [&] { return d; }; 81 auto h = [&] { return d; };
82 auto i = [this] { bar (); }; 82 auto i = [this] { bar (); };
83 auto j = [*this] { bar (); }; // { dg-error "use of deleted function" } 83 auto j = [*this] { bar (); }; // { dg-error "use of deleted function" }
84 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 } 84 // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
85 } 85 }