Debian Codegraph @

gcc/testsuite/g++.dg/cpp23/explicit-obj-lambda11.C

raw
1 // P0847R7
2 // { dg-do compile { target c++23 } }
3
4 // unrelated xobj parameter type in captureless lambdas and lambdas with captures
5
6 struct S0{};
7
8 void test0()
9 {
10 auto f0 = [](this S0){ return 5; }; // { dg-bogus "a lambda with captures may not have an explicit object parameter of an unrelated type" }
11 auto f1 = [x = 42](this S0){ return 5; }; // { dg-error "a lambda with captures may not have an explicit object parameter of an unrelated type" }
12 }
13
14 // instantiation by calling with explicit template arguments
15
16 template<typename T>
17 struct S1 : T {
18 using T::operator();
19 operator int() const {return {};}
20 };
21
22 void test1()
23 {
24 auto s0 = S1{[](this auto&& self) { return self; }}; // { dg-bogus {a lambda with captures may not have an explicit object parameter of an unrelated type} }
25 s0.operator()<int>(); // { dg-bogus {no matching function for call to} }
26
27 auto s1 = S1{[x = 0](this auto&& self) { return self; }}; // { dg-line t1_s1 }
28 s1.operator()<int>(); // { dg-error {no matching function for call to} }
29 // { dg-note {there is 1 candidate} {} { target *-*-* } .-1 }
30 }
31 // { dg-note {candidate 1:} {} { target *-*-* } t1_s1 }
32 // { dg-note {template argument deduction/substitution failed} {} { target *-*-* } t1_s1 }
33 // { dg-error {a lambda with captures may not have an explicit object parameter of an unrelated type} {} { target *-*-* } t1_s1 }
34
35 // instantiation from overload resolution when taking address of call operator
36
37 void test2()
38 {
39 auto f = [x = 42](this auto&&){ return x; }; // { dg-line t2_f }
40
41 int (*fp0)(decltype(f)&) = &decltype(f)::operator();
42 int (*fp1)(int&) = &decltype(f)::operator(); // { dg-error {no matches converting function} }
43 }
44
45 // { dg-error "a lambda with captures may not have an explicit object parameter of an unrelated type" {depends on PR112874} { xfail *-*-* } t2_f }
46 // { dg-note "candidate is" "" { target *-*-* } t2_f }
47