aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/lambda-this3.C
blob: bc54a4c895dc89d211f3c99c27ef58e0f3052112 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// P0806R2
// { dg-do compile { target c++17 } }
// { dg-options "-pedantic" }

struct X {
  int x;
  void foo (int n) {
    auto a1 = [=] { x = n; }; // { dg-bogus "implicit capture" "" { target c++17_down } }
			      // { dg-warning "implicit capture of 'this' via '\\\[=\\\]' is deprecated" "" { target c++20 } .-1 }
			      // { dg-message "add explicit 'this' or '\\\*this' capture" "" { target c++20 } .-2 }
    auto a2 = [=, this] { x = n; };
    // { dg-warning "explicit by-copy capture" "" { target c++17_down } .-1 }
    auto a3 = [=, *this]() mutable { x = n; };
    auto a4 = [&] { x = n; };
    auto a5 = [&, this] { x = n; };
    auto a6 = [&, *this]() mutable { x = n; };

    auto a7 = [=] { // { dg-bogus "implicit capture" "" { target c++17_down } }
		    // { dg-warning "implicit capture of 'this' via '\\\[=\\\]' is deprecated" "" { target c++20 } .-1 }
		    // { dg-message "add explicit 'this' or '\\\*this' capture" "" { target c++20 } .-2 }
      auto a = [=] { // { dg-bogus "implicit capture" "" { target c++17_down } }
		     // { dg-warning "implicit capture of 'this' via '\\\[=\\\]' is deprecated" "" { target c++20 } .-1 }
		     // { dg-message "add explicit 'this' or '\\\*this' capture" "" { target c++20 } .-2 }
	 auto a2 = [=] { x = n; }; // { dg-bogus "implicit capture" "" { target c++17_down } }
				   // { dg-warning "implicit capture of 'this' via '\\\[=\\\]' is deprecated" "" { target c++20 } .-1 }
				   // { dg-message "add explicit 'this' or '\\\*this' capture" "" { target c++20 } .-2 }
      };
    };

    auto a8 = [=, this] {
    // { dg-warning "explicit by-copy capture" "" { target c++17_down } .-1 }
      auto a = [=, this] {
    // { dg-warning "explicit by-copy capture" "" { target c++17_down } .-1 }
	 auto a2 = [=, this] { x = n; };
    // { dg-warning "explicit by-copy capture" "" { target c++17_down } .-1 }
      };
    };

    auto a9 = [=, *this]() mutable {
      auto a = [=, *this]() mutable {
	 auto a2 = [=, *this]() mutable { x = n; };
      };
    };

    auto a10 = [&] {
      auto a = [&] {
	 auto a2 = [&] { x = n; };
      };
    };

    auto a11 = [&, this] {
      auto a = [&, this] {
	 auto a2 = [&, this] { x = n; };
      };
    };

    auto a12 = [&, *this]() mutable {
      auto a = [&, *this]() mutable {
	 auto a2 = [&, *this]() mutable { x = n; };
      };
    };
  }
};