| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } } |
| 3 |
|
| 4 |
// check references are handled as expected. |
| 5 |
|
| 6 |
#include "../coro.h" |
| 7 |
|
| 8 |
// boiler-plate for tests of codegen |
| 9 |
#include "../coro1-ret-int-yield-int.h" |
| 10 |
|
| 11 |
coro1 |
| 12 |
f (int& a_ref, int a_copy) |
| 13 |
{ |
| 14 |
co_yield a_ref + a_copy; |
| 15 |
co_return a_ref + a_copy; |
| 16 |
} |
| 17 |
|
| 18 |
int main () |
| 19 |
{ |
| 20 |
int a_copy = 20; |
| 21 |
int a_ref = 10; |
| 22 |
|
| 23 |
coro1 A = f (a_ref, a_copy); |
| 24 |
A.handle.resume(); // Initial suspend. |
| 25 |
PRINT ("main: [a_copy = 20, a_ref = 10]"); |
| 26 |
|
| 27 |
int y = A.handle.promise().get_value(); |
| 28 |
if (y != 30) |
| 29 |
{ |
| 30 |
PRINTF ("main: co-yield = %d, should be 30\n", y); |
| 31 |
abort (); |
| 32 |
} |
| 33 |
|
| 34 |
a_copy = 5; |
| 35 |
a_ref = 7; |
| 36 |
|
| 37 |
A.handle.resume(); |
| 38 |
PRINT ("main: [a_copy = 5, a_ref = 7]"); |
| 39 |
|
| 40 |
y = A.handle.promise().get_value(); |
| 41 |
if (y != 27) |
| 42 |
{ |
| 43 |
PRINTF ("main: co-ret = %d, should be 27\n", y); |
| 44 |
abort (); |
| 45 |
} |
| 46 |
|
| 47 |
return 0; |
| 48 |
} |