testsuite: don't declare printf in coro.h
[official-gcc.git] / gcc / testsuite / g++.dg / coroutines / torture / call-00-co-aw-arg.C
blob19e3ec1fe68770cd1faf1eb517ede47e7b5f571e
1 // { dg-do run }
3 // Check that we can use co_await as a call parm.
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 int gX = 1;
13 __attribute__((__noinline__))
14 static int
15 foo (int x)
17   return x + 2;
20 /* Function with a single await.  */
21 coro1 
22 f ()
24   gX = foo (co_await 9);
25   co_return gX + 31;
28 int main ()
30   PRINT ("main: create coro1");
31   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     }
40   if (f_coro.handle.done())
41     {
42       PRINT ("main: we should not be 'done' [1]");
43       abort ();
44     }
46   PRINT ("main: resuming [1] (initial suspend)");
47   f_coro.handle.resume();
48   PRINT ("main: resuming [2] (await 9 parm)");
49   f_coro.handle.resume();
51   if (gX != 11)
52     {
53       PRINTF ("main: gX is wrong : %d, should be 11\n", gX);
54       abort ();
55     }
57   /* we should now have returned with the co_return 11 + 31) */
58   if (!f_coro.handle.done())
59     {
60       PRINT ("main: we should be 'done'");
61       abort ();
62     }
64   int y = f_coro.handle.promise().get_value();
65   if (y != 42)
66     {
67       PRINTF ("main: y is wrong : %d, should be 42\n", y);
68       abort ();
69     }
71   PRINT ("main: done");
72   return 0;