testsuite: don't declare printf in coro.h
[official-gcc.git] / gcc / testsuite / g++.dg / coroutines / torture / call-02-temp-co-aw.C
blob8ae07aa7a456723ba42c9cfcab6f894622f509ed
1 // { dg-do run }
3 // Check  foo (compiler temp, co_await).
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 bar (int x, int y)
17   return x + y;
20 /* Function with a compiler temporary and a co_await.  */
21 coro1
22 g ()
24   gX = bar (gX + 8, co_await 2);
25   co_return gX + 31;
28 int main ()
30   PRINT ("main: create coro1");
31   struct coro1 g_coro = g ();
32   PRINT ("main: got coro1 - checking gX");
33   if (gX != 1)
34     {
35       PRINTF ("main: gX is wrong : %d, should be 1\n", gX);
36       abort ();
37     }
38   if (g_coro.handle.done())
39     {
40       PRINT ("main: we should not be 'done' [1]");
41       abort ();
42     }
44   PRINT ("main: resuming [1] (initial suspend)");
45   g_coro.handle.resume();
47   PRINT ("main: resuming [2] (parm 1)");
48   g_coro.handle.resume();
50   if (gX != 11)
51     {
52       PRINTF ("main: gX is wrong : %d, should be 11\n", gX);
53       abort ();
54     }
56   /* we should now have returned with the co_return 11 + 31) */
57   if (!g_coro.handle.done())
58     {
59       PRINT ("main: we should be 'done'");
60       abort ();
61     }
63   int y = g_coro.handle.promise().get_value();
64   if (y != 42)
65     {
66       PRINTF ("main: y is wrong : %d, should be 42\n", y);
67       abort ();
68     }
70   PRINT ("main: done");
71   return 0;