Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/lambda-03-auto-parm-1.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // generic Lambda with auto parm (c++14)
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 int main ()
13 {
14 auto f = [](auto y) -> coro1
15 {
16 PRINT ("coro1: about to return");
17 auto x = y;
18 co_return co_await x + 3;
19 };
20
21 PRINT ("main: create coro1");
22 struct coro1 x = f((int)17);
23 if (x.handle.done())
24 abort();
25
26 x.handle.resume();
27 PRINT ("main: after resume (initial suspend)");
28
29 x.handle.resume();
30 PRINT ("main: after resume (co_await)");
31
32 /* Now we should have the co_returned value. */
33 int y = x.handle.promise().get_value();
34 if ( y != 20 )
35 {
36 PRINTF ("main: wrong result (%d).", y);
37 abort ();
38 }
39
40 if (!x.handle.done())
41 {
42 PRINT ("main: apparently not done...");
43 abort ();
44 }
45 PRINT ("main: returning");
46 return 0;
47 }