Debian Codegraph @

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

raw
1 // P0847R7
2 // { dg-do run { target c++23 } }
3
4 // PR c++/124632
5 // { dg-additional-options "-Wall --param ggc-min-expand=0 --param ggc-min-heapsize=0" }
6
7 // recursive lambdas
8
9 inline constexpr int correct_result = 5 + 4 + 3 + 2 + 1;
10
11 int main()
12 {
13 auto cl0 = [](this auto&& self, int n) -> int { return n ? self(n - 1) + n : 0; };
14 auto cl1 = [](this auto const& self, int n) -> int { return n ? self(n - 1) + n : 0; };
15 auto cl2 = [](this auto self, int n) -> int { return n ? self(n - 1) + n : 0; };
16 auto cl3 = [](this auto&& self, int n) { if (!n) return 0; else return self(n - 1) + n; };
17 auto cl4 = [](this auto const& self, int n){ if (!n) return 0; else return self(n - 1) + n; };
18 auto cl5 = [](this auto self, int n) { if (!n) return 0; else return self(n - 1) + n; };
19 if (cl0(5) != correct_result) __builtin_abort ();
20 if (cl1(5) != correct_result) __builtin_abort ();
21 if (cl2(5) != correct_result) __builtin_abort ();
22 if (cl3(5) != correct_result) __builtin_abort ();
23 if (cl4(5) != correct_result) __builtin_abort ();
24 if (cl5(5) != correct_result) __builtin_abort ();
25 }
26