Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-await-01-with-value.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 /* The simplest valued 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 gX = co_await coro1::suspend_always_intprt{};
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 suspend_always_intprt");
38 f_coro.handle.resume();
39 if (gX != 5)
40 {
41 PRINTF ("main: gX is wrong : %d, should be 5\n", gX);
42 abort ();
43 }
44 /* we should now have returned with the co_return (15) */
45 if (!f_coro.handle.done())
46 {
47 PRINT ("main: we should be 'done' ");
48 abort ();
49 }
50 int y = f_coro.handle.promise().get_value();
51 if (y != 15)
52 {
53 PRINTF ("main: y is wrong : %d, should be 15\n", y);
54 abort ();
55 }
56 PRINT ("main: done");
57 return 0;
58 }