Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-yield-05-co-aw.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 #include "../coro1-ret-int-yield-int.h"
10
11 struct coro1
12 f () noexcept
13 {
14 PRINT ("f: about to yield");
15 co_yield co_await coro1::suspend_always_intprt(42);
16
17 PRINT ("f: about to return 6174");
18 co_return 6174;
19 }
20
21 int main ()
22 {
23 PRINT ("main: create coro1");
24 struct coro1 x = f ();
25 if (x.handle.done())
26 abort();
27
28 PRINT ("main: resuming (initial suspend)");
29 x.handle.resume();
30 PRINT ("main: resuming (await intprt)");
31 x.handle.resume();
32
33 PRINT ("main: after resume (2)");
34 int y = x.handle.promise().get_value();
35 if ( y != 42 )
36 abort ();
37 PRINT ("main: apparently got 42");
38
39 PRINT ("main: got coro1 - resuming (co_yield)");
40 if (x.handle.done())
41 abort();
42 x.handle.resume();
43
44 PRINT ("main: after resume (co_yield)");
45 y = x.handle.promise().get_value();
46 if ( y != 6174 )
47 abort ();
48 PRINT ("main: apparently got 6174");
49 if (!x.handle.done())
50 {
51 PRINT ("main: apparently not done...");
52 abort ();
53 }
54 PRINT ("main: returning");
55 return 0;
56 }