testsuite: don't declare printf in coro.h
[official-gcc.git] / gcc / testsuite / g++.dg / coroutines / torture / co-await-01-with-value.C
blobddff64530b3d9ce71fbd0eb002cda2a6e2bffe61
1 //  { dg-do run }
3 /* The simplest valued co_await we can do.  */
5 #include "../coro.h"
7 // boiler-plate for tests of codegen
8 #include "../coro1-ret-int-yield-int.h"
10 int gX = 1;
12 coro1
13 f ()
15   gX = co_await coro1::suspend_always_intprt{};
16   co_return gX + 10;
19 int main ()
21   PRINT ("main: create coro1");
22   struct coro1 f_coro = f ();
23   PRINT ("main: got coro1 - checking gX");
24   if (gX != 1)
25     {
26       PRINTF ("main: gX is wrong : %d, should be 1\n", gX);
27       abort ();
28     }
29   if (f_coro.handle.done())
30     {
31       PRINT ("main: we should not be 'done' [1]");
32       abort ();
33     }
34   PRINT ("main: resuming [1] initial suspend");
35   f_coro.handle.resume();
36   PRINT ("main: resuming [2] co_await suspend_always_intprt");
37   f_coro.handle.resume();
38   if (gX != 5)
39     {
40       PRINTF ("main: gX is wrong : %d, should be 5\n", gX);
41       abort ();
42     }
43   /* we should now have returned with the co_return (15) */
44   if (!f_coro.handle.done())
45     {
46       PRINT ("main: we should be 'done' ");
47       abort ();
48     }
49   int y = f_coro.handle.promise().get_value();
50   if (y != 15)
51     {
52       PRINTF ("main: y is wrong : %d, should be 15\n", y);
53       abort ();
54     }
55   PRINT ("main: done");
56   return 0;