145
|
1 // { dg-do run }
|
|
2
|
|
3 // Check co_return function (co_await)
|
|
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 __attribute__((__noinline__))
|
|
12 static int
|
|
13 foo (int x)
|
|
14 {
|
|
15 return x + 2;
|
|
16 }
|
|
17
|
|
18 struct coro1
|
|
19 f () noexcept
|
|
20 {
|
|
21 PRINT ("coro1: about to return");
|
|
22 co_return foo (co_await 5);
|
|
23 }
|
|
24
|
|
25 int main ()
|
|
26 {
|
|
27 PRINT ("main: create coro1");
|
|
28 struct coro1 x = f ();
|
|
29 PRINT ("main: got coro1 - resuming");
|
|
30 if (x.handle.done())
|
|
31 abort();
|
|
32
|
|
33 x.handle.resume();
|
|
34 PRINT ("main: after resume 1 (initial suspend)");
|
|
35 x.handle.resume();
|
|
36 PRINT ("main: after resume 2 (await parm)");
|
|
37
|
|
38 int y = x.handle.promise().get_value();
|
|
39 if ( y != 7 )
|
|
40 abort ();
|
|
41 if (!x.handle.done())
|
|
42 {
|
|
43 PRINT ("main: apparently not done...");
|
|
44 abort ();
|
|
45 }
|
|
46 PRINT ("main: returning");
|
|
47 return 0;
|
|
48 }
|