Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/lambda-06-multi-capture.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // lambda with parm and local state
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 int a_ref = 10;
15
16 auto f = [&, a_copy]() -> coro1
17 {
18 co_return a_ref + a_copy;
19 };
20
21 {
22 coro1 A = f ();
23 A.handle.resume();
24 PRINT ("main: [a_copy = 20, a_ref = 10]");
25
26 int y = A.handle.promise().get_value();
27 if (y != 30)
28 {
29 PRINTF ("main: A co-ret = %d, should be 30\n", y);
30 abort ();
31 }
32 }
33
34 a_copy = 5;
35 a_ref = 7;
36
37 coro1 B = f ();
38 B.handle.resume();
39 PRINT ("main: [a_copy = 5, a_ref = 7]");
40
41 int y = B.handle.promise().get_value();
42 if (y != 27)
43 {
44 PRINTF ("main: B co-ret = %d, should be 27\n", y);
45 abort ();
46 }
47
48 return 0;
49 }