Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-yield-06-fun-parm.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // Check co_return co_await
5
6 #include "../coro.h"
7
8 // boiler-plate for tests of codegen
9 #define USE_AWAIT_TRANSFORM
10 #include "../coro1-ret-int-yield-int.h"
11
12 __attribute__((__noinline__))
13 static int
14 foo (int x)
15 {
16 return x + 2;
17 }
18
19 /* Function with a single await. */
20 struct coro1
21 f () noexcept
22 {
23 PRINT ("f: about to yield");
24 co_yield foo (co_await 40);
25
26 PRINT ("f: about to return 6174");
27 co_return 6174;
28 }
29
30 int main ()
31 {
32 PRINT ("main: create coro1");
33 struct coro1 x = f ();
34 if (x.handle.done())
35 abort();
36
37 PRINT ("main: resuming (initial suspend)");
38 x.handle.resume();
39 PRINT ("main: resuming (await intprt)");
40 x.handle.resume();
41
42 PRINT ("main: after resume (2)");
43 int y = x.handle.promise().get_value();
44 if ( y != 42 )
45 abort ();
46 PRINT ("main: apparently got 42");
47
48 PRINT ("main: got coro1 - resuming (co_yield)");
49 if (x.handle.done())
50 abort();
51 x.handle.resume();
52
53 PRINT ("main: after resume (co_yield)");
54 y = x.handle.promise().get_value();
55 if ( y != 6174 )
56 abort ();
57 PRINT ("main: apparently got 6174");
58 if (!x.handle.done())
59 {
60 PRINT ("main: apparently not done...");
61 abort ();
62 }
63 PRINT ("main: returning");
64 return 0;
65 }