Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/lambda-09-init-captures.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // lambda with initialized captures
5
6 #include "../coro.h"
7
8 // boiler-plate for tests of codegen
9 #include "../coro1-ret-int-yield-int.h"
10
11 int main ()
12 {
13 int a_copy = 20;
14
15 auto f = [&a_ref = a_copy, a_copy = a_copy + 10]() -> coro1
16 {
17 a_ref += 20;
18 co_return a_ref + a_copy;
19 };
20
21 {
22 coro1 A = f ();
23 A.handle.resume();
24 if (a_copy != 40)
25 {
26 PRINT ("main: [a_copy = 40]");
27 abort ();
28 }
29
30 int y = A.handle.promise().get_value();
31 if (y != 70)
32 {
33 PRINTF ("main: A co-ret = %d, should be 70\n", y);
34 abort ();
35 }
36 }
37
38 a_copy = 5;
39
40 coro1 B = f ();
41 B.handle.resume();
42 if (a_copy != 25)
43 {
44 PRINT ("main: [a_copy = 25]");
45 abort ();
46 }
47
48 int y = B.handle.promise().get_value();
49 if (y != 55)
50 {
51 PRINTF ("main: B co-ret = %d, should be 55\n", y);
52 abort ();
53 }
54
55 return 0;
56 }