Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/lambda-05-capture-copy-local.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 local = 31;
14
15 auto f = [=](int start) -> coro1
16 {
17 int value = start;
18 PRINT ("f: about to yield start");
19 co_yield start;
20
21 value -= local;
22 PRINT ("f: about to yield (value-31)");
23 co_yield value;
24
25 value += 6163;
26 PRINT ("f: about to return (value+6163)");
27 co_return value;
28 };
29
30 PRINT ("main: create coro1");
31 coro1 x = f (42);
32 PRINT ("main: got coro1 - resuming (1)");
33 if (x.handle.done())
34 abort();
35 x.handle.resume();
36 PRINT ("main: after resume (1)");
37 int y = x.handle.promise().get_value();
38 if ( y != 42 )
39 abort ();
40 PRINT ("main: apparently got 42 - resuming (2)");
41 if (x.handle.done())
42 abort();
43 x.handle.resume();
44 PRINT ("main: after resume (2)");
45 y = x.handle.promise().get_value();
46 if ( y != 11 )
47 abort ();
48 PRINT ("main: apparently got 11 - resuming (3)");
49 if (x.handle.done())
50 {
51 PRINT ("main: done?");
52 abort();
53 }
54 x.handle.resume();
55 PRINT ("main: after resume (2) checking return");
56 y = x.handle.promise().get_value();
57 if ( y != 6174 )
58 abort ();
59 PRINT ("main: apparently got 6174");
60 if (!x.handle.done())
61 {
62 PRINT ("main: apparently not done...");
63 abort ();
64 }
65 PRINT ("main: returning");
66 return 0;
67 }