Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-await-09-pair.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 #include "../coro.h"
5
6 // boiler-plate for tests of codegen
7 #define USE_AWAIT_TRANSFORM
8 #include "../coro1-ret-int-yield-int.h"
9
10 /* Valued with an await_transform. */
11 int gX = 1;
12 coro1 f ()
13 {
14 gX = co_await 11 + co_await 15;
15 co_return gX + 31;
16 }
17
18 int main ()
19 {
20 PRINT ("main: create coro1");
21 struct coro1 f_coro = f ();
22 PRINT ("main: got coro1 - checking gX");
23 if (gX != 1)
24 {
25 PRINTF ("main: gX is wrong : %d, should be 1\n", gX);
26 abort ();
27 }
28 if (f_coro.handle.done())
29 {
30 PRINT ("main: we should not be 'done' [1]");
31 abort ();
32 }
33 PRINT ("main: resuming [1] (initial suspend)");
34 f_coro.handle.resume();
35 PRINT ("main: resuming [2] one side of add");
36 f_coro.handle.resume();
37 PRINT ("main: resuming [3] other side of add");
38 f_coro.handle.resume();
39 if (gX != 26)
40 {
41 PRINTF ("main: gX is wrong : %d, should be 26\n", gX);
42 abort ();
43 }
44 /* we should now have returned with the co_return (57) */
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 != 57)
52 {
53 PRINTF ("main: y is wrong : %d, should be 57\n", y);
54 abort ();
55 }
56 PRINT ("main: done");
57 return 0;
58 }