Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-ret-11-co-ret-co-await.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 ("coro1: about to return");
15 co_return co_await coro1::suspend_always_intprt{};
16 }
17
18 int main ()
19 {
20 PRINT ("main: create coro1");
21 struct coro1 x = f ();
22 PRINT ("main: got coro1 - resuming");
23 if (x.handle.done())
24 abort();
25
26 x.handle.resume();
27 PRINT ("main: after resume 1 (initial suspend)");
28 x.handle.resume();
29 PRINT ("main: after resume 2 (await intprt)");
30
31 int y = x.handle.promise().get_value();
32 if ( y != 5 )
33 abort ();
34 if (!x.handle.done())
35 {
36 PRINT ("main: apparently not done...");
37 abort ();
38 }
39 PRINT ("main: returning");
40 return 0;
41 }