| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } } |
| 3 |
|
| 4 |
// Test that we can use a function param in a co_xxxx status. |
| 5 |
|
| 6 |
#include "../coro.h" |
| 7 |
|
| 8 |
// boiler-plate for tests of codegen |
| 9 |
#include "../coro1-ret-int-yield-int.h" |
| 10 |
|
| 11 |
int main () |
| 12 |
{ |
| 13 |
int val; |
| 14 |
|
| 15 |
auto f = [&] (int x) -> coro1 |
| 16 |
{ |
| 17 |
if (val + x > 25) |
| 18 |
{ |
| 19 |
PRINT ("coro1: about to return k"); |
| 20 |
co_return 6174; |
| 21 |
} |
| 22 |
else if (val + x > 20) |
| 23 |
{ |
| 24 |
PRINTF ("coro1: about to co-return %d\n", val + x); |
| 25 |
co_return val + x; |
| 26 |
} |
| 27 |
else if (val + x > 5) |
| 28 |
{ |
| 29 |
PRINTF ("coro1: about to co-return %d\n", val); |
| 30 |
co_return val; |
| 31 |
} |
| 32 |
else |
| 33 |
{ |
| 34 |
PRINT ("coro1: about to return 0"); |
| 35 |
co_return 0; |
| 36 |
} |
| 37 |
}; |
| 38 |
|
| 39 |
PRINT ("main: create coro1"); |
| 40 |
|
| 41 |
val = 20; // We should get this by ref. |
| 42 |
int arg = 5; // and this as a regular parm. |
| 43 |
|
| 44 |
coro1 x = f (arg); |
| 45 |
PRINT ("main: got coro1 - resuming"); |
| 46 |
if (x.handle.done()) |
| 47 |
abort(); |
| 48 |
x.handle.resume(); |
| 49 |
PRINT ("main: after resume"); |
| 50 |
int y = x.handle.promise().get_value(); |
| 51 |
if ( y != 25 ) |
| 52 |
abort (); |
| 53 |
if (!x.handle.done()) |
| 54 |
{ |
| 55 |
PRINT ("main: apparently not done..."); |
| 56 |
abort (); |
| 57 |
} |
| 58 |
PRINT ("main: returning"); |
| 59 |
return 0; |
| 60 |
} |