Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-ret-16-simple-control-flow.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // Test returning an int.
5 // We will use the promise to contain this to avoid having to include
6 // additional C++ headers.
7
8 #include "../coro.h"
9
10 // boiler-plate for tests of codegen
11 #include "../coro1-ret-int-yield-int.h"
12
13 struct coro1
14 f (int v)
15 {
16 if (co_await coro1::suspend_always_intprt{v} == 10)
17 co_return 6174;
18 else
19 {
20 int v = 42;
21 PRINT ("coro1: about to return");
22 co_return v;
23 }
24 }
25
26 int main ()
27 {
28 PRINT ("main: create coro1");
29 struct coro1 x = f (10);
30 PRINT ("main: got coro1 - resuming");
31 if (x.handle.done())
32 abort();
33 // initial susp
34 x.handle.resume();
35 PRINT ("main: after resume");
36 // if condition
37 x.handle.resume();
38 int y = x.handle.promise().get_value();
39 if ( y != 6174 )
40 abort ();
41 if (!x.handle.done())
42 {
43 PRINT ("main: apparently not done...");
44 abort ();
45 }
46 PRINT ("main: returning");
47 return 0;
48 }