| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } } |
| 3 |
|
| 4 |
// Test of basic await transform, no local state. |
| 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 gX = 1; |
| 13 |
|
| 14 |
coro1 |
| 15 |
f () |
| 16 |
{ |
| 17 |
gX = co_await 11; |
| 18 |
co_return gX + 31; |
| 19 |
} |
| 20 |
|
| 21 |
int main () |
| 22 |
{ |
| 23 |
PRINT ("main: create coro1"); |
| 24 |
struct coro1 f_coro = f (); |
| 25 |
PRINT ("main: got coro1 - checking gX"); |
| 26 |
if (gX != 1) |
| 27 |
{ |
| 28 |
PRINTF ("main: gX is wrong : %d, should be 1\n", gX); |
| 29 |
abort (); |
| 30 |
} |
| 31 |
if (f_coro.handle.done()) |
| 32 |
{ |
| 33 |
PRINT ("main: we should not be 'done' [1]"); |
| 34 |
abort (); |
| 35 |
} |
| 36 |
PRINT ("main: resuming [1] initial suspend"); |
| 37 |
f_coro.handle.resume(); |
| 38 |
PRINT ("main: resuming [2] co_await"); |
| 39 |
f_coro.handle.resume(); |
| 40 |
if (gX != 11) |
| 41 |
{ |
| 42 |
PRINTF ("main: gX is wrong : %d, should be 11\n", gX); |
| 43 |
abort (); |
| 44 |
} |
| 45 |
/* we should now have returned with the co_return (15) */ |
| 46 |
if (!f_coro.handle.done()) |
| 47 |
{ |
| 48 |
PRINT ("main: we should be 'done' "); |
| 49 |
abort (); |
| 50 |
} |
| 51 |
int y = f_coro.handle.promise().get_value(); |
| 52 |
if (y != 42) |
| 53 |
{ |
| 54 |
PRINTF ("main: y is wrong : %d, should be 42\n", y); |
| 55 |
abort (); |
| 56 |
} |
| 57 |
PRINT ("main: done"); |
| 58 |
return 0; |
| 59 |
} |