testsuite: don't declare printf in coro.h
[official-gcc.git] / gcc / testsuite / g++.dg / coroutines / torture / func-params-05.C
blob8bdb2b5d0f780933b32d44b1ab19ae129852d048
1 //  { dg-do run }
3 // Test that we can manage a constructed param reference
5 #include "../coro.h"
7 // boiler-plate for tests of codegen
8 #include "../coro1-ret-int-yield-int.h"
10 // Require a ctor.
11 struct nontriv {
12   int a, b, c;
13   nontriv (int _a, int _b, int _c) : a(_a), b(_b), c(_c) {}
14   virtual int getA () { return a; }
17 struct coro1
18 f (nontriv &t) noexcept
20   if (t.a > 30)
21     {
22       PRINTF ("coro1: about to return %d", t.b);
23       co_return t.b;
24     }
25   else if (t.a > 20)
26     {
27       PRINTF ("coro1: about to co-return %d", t.c);
28       co_return t.c;
29     }
30   else
31     {
32       PRINT ("coro1: about to return 0");
33       co_return 0;
34     }
37 int main ()
39   PRINT ("main: create coro1");
40   nontriv test (25, 6174, 42);
41   struct coro1 x = f (test);
42   PRINT ("main: got coro1 - resuming");
43   if (x.handle.done())
44     abort();
45   x.handle.resume();
46   PRINT ("main: after resume");
47   int y = x.handle.promise().get_value();
48   if ( y != 42 )
49     abort ();
50   if (!x.handle.done())
51     {
52       PRINT ("main: apparently not done...");
53       abort ();
54     }
55   PRINT ("main: returning");
56   return 0;