testsuite: don't declare printf in coro.h
[official-gcc.git] / gcc / testsuite / g++.dg / coroutines / torture / co-await-04-control-flow.C
blobfd201f904816db5b4d1081198d081596d662dfb8
1 //  { dg-do run }
3 // Check correct operation of await transform.
5 #include "../coro.h"
7 // boiler-plate for tests of codegen
8 #define USE_AWAIT_TRANSFORM
9 #include "../coro1-ret-int-yield-int.h"
11 /* Valued with an await_transform.  */
12 int gX = 1;
13 int y = 30;
15 coro1
16 f ()
18   if (gX < 12) {
19 L1:
20     gX += y;
21     gX += co_await 11;
22   } else
23 L2:
24     gX += co_await 12;
25     
26   co_return gX;
29 int main ()
31   PRINT ("main: create coro1");
32   struct coro1 f_coro = f ();
33   PRINT ("main: got coro1 - checking gX");
34   if (gX != 1)
35     {
36       PRINTF ("main: gX is wrong : %d, should be 1\n", gX);
37       abort ();
38     }
39   PRINT ("main: gX OK -- looping");
40   do {
41     PRINTF ("main: gX : %d \n", gX);
42     f_coro.handle.resume();
43   } while (!f_coro.handle.done());
44   int y = f_coro.handle.promise().get_value();
45   if (y != 42)
46     {
47       PRINTF ("main: y is wrong : %d, should be 42\n", y);
48       abort ();
49     }
50   PRINT ("main: done");
51   return 0;