c++: P0847R7 (deducing this) - xobj lambdas. [PR102609]
[official-gcc.git] / gcc / testsuite / g++.dg / cpp23 / explicit-obj-lambda2.C
blob827197a66674f67ca46a0ca16d34d797bac91276
1 // P0847R7
2 // { dg-do run { target c++23 } }
4 // recursive lambdas
6 inline constexpr int correct_result = 5 + 4 + 3 + 2 + 1; 
8 int main()
10   auto cl0 = [](this auto&& self, int n)      -> int { return n ? self(n - 1) + n : 0; };
11   auto cl1 = [](this auto const& self, int n) -> int { return n ? self(n - 1) + n : 0; };
12   auto cl2 = [](this auto self, int n)        -> int { return n ? self(n - 1) + n : 0; };
13   auto cl3 = [](this auto&& self, int n)     { if (!n) return 0; else return self(n - 1) + n; };
14   auto cl4 = [](this auto const& self, int n){ if (!n) return 0; else return self(n - 1) + n; };
15   auto cl5 = [](this auto self, int n)       { if (!n) return 0; else return self(n - 1) + n; };
16   if (cl0(5) != correct_result) __builtin_abort ();
17   if (cl1(5) != correct_result) __builtin_abort ();
18   if (cl2(5) != correct_result) __builtin_abort ();
19   if (cl3(5) != correct_result) __builtin_abort ();
20   if (cl4(5) != correct_result) __builtin_abort ();
21   if (cl5(5) != correct_result) __builtin_abort ();