testsuite: don't declare printf in coro.h
[official-gcc.git] / gcc / testsuite / g++.dg / coroutines / torture / class-05-lambda-capture-copy-local.C
blob9bb76d246c3b60e722332336a5b29d9f676d41c9
1 // { dg-do run }
3 // template parm in a class
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 template <typename T>
12 class foo
14   public:
15   auto get_lam (int parm)
16     {
17       int local = 3;
18       auto l = [=](T y) -> coro1
19       {
20         T x = y;
21         co_return co_await x + y + local;
22       };
23       return l;
24     }
27 int main ()
29   foo<int> inst {};
30   auto ll = inst.get_lam (10);
32   PRINT ("main: create coro1");
33   int arg = 17; // avoid a dangling reference
34   coro1 x = ll (arg);
35   if (x.handle.done())
36     abort();
38   x.handle.resume();
39   PRINT ("main: after resume (initial suspend)");
41   x.handle.resume();
42   PRINT ("main: after resume (co_await)");
44   /* Now we should have the co_returned value.  */
45   int y = x.handle.promise().get_value();
46   if ( y != 37 )
47     {
48       PRINTF ("main: wrong result (%d).", y);
49       abort ();
50     }
52   if (!x.handle.done())
53     {
54       PRINT ("main: apparently not done...");
55       abort ();
56     }
57   PRINT ("main: returning");
58   return 0;