Debian Codegraph @

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

raw
1 // P0847R7
2 // { dg-do run { target c++23 } }
3
4 // calling captureless lambda call operator with unrelated explicit object parameter
5 // through function pointer
6
7 int main()
8 {
9 auto f0 = [](this auto self) { return self; };
10 auto fp0_value = static_cast<int(*)(int) >(&decltype(f0)::operator());
11 auto fp0_lref = static_cast<int(*)(int&) >(&decltype(f0)::operator());
12 auto fp0_rref = static_cast<int(*)(int&&) >(&decltype(f0)::operator());
13 auto fp0_constlref = static_cast<int(*)(int const&) >(&decltype(f0)::operator());
14 auto fp0_constrref = static_cast<int(*)(int const&&)>(&decltype(f0)::operator());
15
16 auto f1 = [](this auto&& self) { return self; };
17 auto fp1_lref = static_cast<int(*)(int&) >(&decltype(f1)::operator());
18 auto fp1_rref = static_cast<int(*)(int&&) >(&decltype(f1)::operator());
19 auto fp1_constlref = static_cast<int(*)(int const&) >(&decltype(f1)::operator());
20 auto fp1_constrref = static_cast<int(*)(int const&&)>(&decltype(f1)::operator());
21
22 // both are needed for lvalue/rvalue overloads
23 #define MAGIC 42
24 int magic = MAGIC;
25
26 if (fp0_value (magic) != magic)
27 __builtin_abort ();
28 if (fp0_lref (magic) != magic)
29 __builtin_abort ();
30 if (fp0_rref (MAGIC) != magic)
31 __builtin_abort ();
32 if (fp0_constlref (magic) != magic)
33 __builtin_abort ();
34 if (fp0_constrref (MAGIC) != magic)
35 __builtin_abort ();
36
37 if (fp1_lref (magic) != magic)
38 __builtin_abort ();
39 if (fp1_rref (MAGIC) != magic)
40 __builtin_abort ();
41 if (fp1_constlref (magic) != magic)
42 __builtin_abort ();
43 if (fp1_constrref (MAGIC) != magic)
44 __builtin_abort ();
45 }
46