Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-await-08-cascade.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // Check cascaded co_await operations.
5
6 #include "../coro.h"
7
8 #define USE_AWAIT_TRANSFORM
9 #include "../coro1-ret-int-yield-int.h"
10
11 /* Valued with an await_transform. */
12 int gX = 1;
13 coro1 f ()
14 {
15 /* We are going to use an await transform that takes a long, the
16 await_resume squares it.
17 so we get 11 ** 4, 14641. */
18 gX = (int) co_await co_await 11L;
19 co_return gX + 31;
20 }
21
22 int main ()
23 {
24 PRINT ("main: create coro1");
25 struct coro1 f_coro = f ();
26 PRINT ("main: got coro1 - checking gX");
27 if (gX != 1)
28 {
29 PRINTF ("main: gX is wrong : %d, should be 1\n", gX);
30 abort ();
31 }
32 if (f_coro.handle.done())
33 {
34 PRINT ("main: we should not be 'done' [1]");
35 abort ();
36 }
37 PRINT ("main: resuming [1] - inital suspend");
38 f_coro.handle.resume();
39
40 PRINT ("main: resuming [2] - nested");
41 f_coro.handle.resume();
42 PRINT ("main: resuming [3] - outer");
43 f_coro.handle.resume();
44
45 if (gX != 14641)
46 {
47 PRINTF ("main: gX is wrong : %d, should be 14641\n", gX);
48 abort ();
49 }
50 /* we should now have returned with the co_return (14672) */
51 if (!f_coro.handle.done())
52 {
53 PRINT ("main: we should be 'done' ");
54 abort ();
55 }
56 int y = f_coro.handle.promise().get_value();
57 if (y != 14672)
58 {
59 PRINTF ("main: y is wrong : %d, should be 14672\n", y);
60 abort ();
61 }
62 PRINT ("main: done");
63 return 0;
64 }