Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-await-00-trivial.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // The simplest co_await we can do.
5
6 #include "../coro.h"
7
8 // boiler-plate for tests of codegen
9 #include "../coro1-ret-int-yield-int.h"
10
11 int gX = 1;
12
13 coro1
14 f ()
15 {
16 co_await coro1::suspend_always_prt{};
17 co_return gX + 10;
18 }
19
20 int main ()
21 {
22 PRINT ("main: create coro1");
23 struct coro1 f_coro = f ();
24 PRINT ("main: got coro1 - checking gX");
25 if (gX != 1)
26 {
27 PRINTF ("main: gX is wrong : %d, should be 1\n", gX);
28 abort ();
29 }
30 if (f_coro.handle.done())
31 {
32 PRINT ("main: we should not be 'done' [1]");
33 abort ();
34 }
35 PRINT ("main: resuming [1] initial suspend");
36 f_coro.handle.resume();
37 PRINT ("main: resuming [2] co_await");
38 f_coro.handle.resume();
39 /* we should now have returned with the co_return (15) */
40 if (!f_coro.handle.done())
41 {
42 PRINT ("main: we should be 'done' ");
43 abort ();
44 }
45 int y = f_coro.handle.promise().get_value();
46 if (y != 11)
47 {
48 PRINTF ("main: y is wrong : %d, should be 11\n", y);
49 abort ();
50 }
51 PRINT ("main: done");
52 return 0;
53 }