Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/class-04-lambda-1.C

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