| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } } |
| 3 |
|
| 4 |
// Check correct operation of co_await in a loop without 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 |
/* Valued with an await_transform. */ |
| 13 |
int gX = 1; |
| 14 |
|
| 15 |
coro1 |
| 16 |
f () |
| 17 |
{ |
| 18 |
for (;;) |
| 19 |
{ |
| 20 |
gX += co_await 11; |
| 21 |
if (gX > 100) |
| 22 |
break; |
| 23 |
} |
| 24 |
co_return gX; |
| 25 |
} |
| 26 |
|
| 27 |
int main () |
| 28 |
{ |
| 29 |
PRINT ("main: create coro1"); |
| 30 |
struct coro1 f_coro = f (); |
| 31 |
PRINT ("main: got coro1 - checking gX"); |
| 32 |
if (gX != 1) |
| 33 |
{ |
| 34 |
PRINTF ("main: gX is wrong : %d, should be 1\n", gX); |
| 35 |
abort (); |
| 36 |
} |
| 37 |
PRINT ("main: gX OK -- looping"); |
| 38 |
do { |
| 39 |
PRINTF ("main: gX : %d \n", gX); |
| 40 |
f_coro.handle.resume(); |
| 41 |
} while (!f_coro.handle.done()); |
| 42 |
|
| 43 |
int y = f_coro.handle.promise().get_value(); |
| 44 |
// first value above 100 is 10*11 + 1. |
| 45 |
if (y != 111) |
| 46 |
{ |
| 47 |
PRINTF ("main: y is wrong : %d, should be 111\n", y); |
| 48 |
abort (); |
| 49 |
} |
| 50 |
PRINT ("main: done"); |
| 51 |
return 0; |
| 52 |
} |