Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/lambda-04-templ-parm.C

raw
1 // { dg-do run }
2 // { dg-additional-options "-std=c++2a" }
3 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
4
5 // generic Lambda with template parm (from c++20)
6
7 #include "../coro.h"
8
9 // boiler-plate for tests of codegen
10 #define USE_AWAIT_TRANSFORM
11 #include "../coro1-ret-int-yield-int.h"
12
13 int main ()
14 {
15 auto f = []<typename T>(T y) -> coro1
16 {
17 PRINT ("coro1: about to return");
18 T x = y;
19 co_return co_await x + 3;
20 };
21
22 PRINT ("main: create coro1");
23 coro1 x = f.operator()<int>(17);
24 if (x.handle.done())
25 abort();
26
27 x.handle.resume();
28 PRINT ("main: after resume (initial suspend)");
29
30 x.handle.resume();
31 PRINT ("main: after resume (co_await)");
32
33 /* Now we should have the co_returned value. */
34 int y = x.handle.promise().get_value();
35 if ( y != 20 )
36 {
37 PRINTF ("main: wrong result (%d).", y);
38 abort ();
39 }
40
41 if (!x.handle.done())
42 {
43 PRINT ("main: apparently not done...");
44 abort ();
45 }
46 PRINT ("main: returning");
47 return 0;
48 }