Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/lambda-01-co-ret-parm.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // Lambda with parm
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 auto f = [](int x) -> coro1
14 {
15 if (x > 30)
16 {
17 PRINT ("coro1: about to return k");
18 co_return 6174;
19 }
20 else if (x > 20)
21 {
22 PRINT ("coro1: about to return the answer");
23 co_return 42;
24 }
25 else
26 {
27 PRINT ("coro1: about to return 0");
28 co_return 0;
29 }
30 };
31
32 PRINT ("main: create coro1");
33 coro1 x = f (25);
34 PRINT ("main: got coro1 - resuming");
35 if (x.handle.done())
36 abort();
37 x.handle.resume();
38 PRINT ("main: after resume");
39 int y = x.handle.promise().get_value();
40 if ( y != 42 )
41 abort ();
42 if (!x.handle.done())
43 {
44 PRINT ("main: apparently not done...");
45 abort ();
46 }
47 PRINT ("main: returning");
48 return 0;
49 }