145
|
1 // { dg-do run }
|
|
2
|
|
3 // template parm in a class
|
|
4
|
|
5 #include "../coro.h"
|
|
6
|
|
7 // boiler-plate for tests of codegen
|
|
8 #define USE_AWAIT_TRANSFORM
|
|
9 #include "../coro1-ret-int-yield-int.h"
|
|
10
|
|
11 template <typename T>
|
|
12 class foo
|
|
13 {
|
|
14 public:
|
|
15 auto get_lam ()
|
|
16 {
|
|
17 auto l = [](T y) -> coro1
|
|
18 {
|
|
19 T x = y;
|
|
20 co_return co_await x + 3;
|
|
21 };
|
|
22 return l;
|
|
23 }
|
|
24 };
|
|
25
|
|
26 int main ()
|
|
27 {
|
|
28 foo<int> inst {};
|
|
29 auto ll = inst.get_lam ();
|
|
30
|
|
31 PRINT ("main: create coro1");
|
|
32 int arg = 17; // avoid a dangling reference
|
|
33 coro1 x = ll (arg);
|
|
34 if (x.handle.done())
|
|
35 abort();
|
|
36
|
|
37 x.handle.resume();
|
|
38 PRINT ("main: after resume (initial suspend)");
|
|
39
|
|
40 x.handle.resume();
|
|
41 PRINT ("main: after resume (co_await)");
|
|
42
|
|
43 /* Now we should have the co_returned value. */
|
|
44 int y = x.handle.promise().get_value();
|
|
45 if ( y != 20 )
|
|
46 {
|
|
47 PRINTF ("main: wrong result (%d).", y);
|
|
48 abort ();
|
|
49 }
|
|
50
|
|
51 if (!x.handle.done())
|
|
52 {
|
|
53 PRINT ("main: apparently not done...");
|
|
54 abort ();
|
|
55 }
|
|
56 PRINT ("main: returning");
|
|
57 return 0;
|
|
58 }
|