| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } } |
| 3 |
|
| 4 |
// Test promise construction from function args list. |
| 5 |
|
| 6 |
#include "../coro.h" |
| 7 |
|
| 8 |
// boiler-plate for tests of codegen |
| 9 |
#include "../coro1-ret-int-yield-int.h" |
| 10 |
|
| 11 |
struct coro1 |
| 12 |
f (int x) noexcept |
| 13 |
{ |
| 14 |
PRINT ("coro1: about to return"); |
| 15 |
co_return 42; |
| 16 |
} |
| 17 |
|
| 18 |
int main () |
| 19 |
{ |
| 20 |
PRINT ("main: create coro1"); |
| 21 |
struct coro1 x = f (555); |
| 22 |
int y = x.handle.promise().get_value(); |
| 23 |
if ( y != 555 ) |
| 24 |
{ |
| 25 |
PRINT ("main: incorrect ctor value"); |
| 26 |
abort (); |
| 27 |
} |
| 28 |
PRINTF ("main: after coro1 ctor %d - now resuming\n", y); |
| 29 |
if (x.handle.done()) |
| 30 |
abort(); |
| 31 |
x.handle.resume(); |
| 32 |
PRINT ("main: after resume"); |
| 33 |
y = x.handle.promise().get_value(); |
| 34 |
if ( y != 42 ) |
| 35 |
abort (); |
| 36 |
if (!x.handle.done()) |
| 37 |
{ |
| 38 |
PRINT ("main: apparently not done..."); |
| 39 |
abort (); |
| 40 |
} |
| 41 |
PRINT ("main: returning"); |
| 42 |
return 0; |
| 43 |
} |