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