| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } } |
| 3 |
|
| 4 |
// Test that we copy simple parms correctly by value, reference or |
| 5 |
// rvalue reference. |
| 6 |
|
| 7 |
#include "../coro.h" |
| 8 |
|
| 9 |
// boiler-plate for tests of codegen |
| 10 |
#include "../coro1-refs-and-ctors.h" |
| 11 |
|
| 12 |
coro1 |
| 13 |
my_coro (int v1, int& v2, int&& v3) |
| 14 |
{ |
| 15 |
co_yield v1 + v2 + v3; |
| 16 |
co_return v1 + v2 + v3; |
| 17 |
} |
| 18 |
|
| 19 |
int main () |
| 20 |
{ |
| 21 |
PRINT ("main: create coro1"); |
| 22 |
int lv = 1; |
| 23 |
int lvr = 2; |
| 24 |
coro1 x = my_coro (lv, lvr, lvr+2); |
| 25 |
|
| 26 |
if (x.handle.done()) |
| 27 |
abort(); |
| 28 |
|
| 29 |
x.handle.resume(); |
| 30 |
PRINT ("main: after resume (initial suspend)"); |
| 31 |
|
| 32 |
/* Now we should have the co_yielded value. */ |
| 33 |
int y = x.handle.promise().get_value(); |
| 34 |
if ( y != 7 ) |
| 35 |
{ |
| 36 |
PRINTF ("main: wrong result (%d).", y); |
| 37 |
abort (); |
| 38 |
} |
| 39 |
|
| 40 |
/* So we should be suspended at the yield, now change the |
| 41 |
values so that we can determine that the reference persists |
| 42 |
and the copy was made correctly. */ |
| 43 |
lv = 5; // should be ignored |
| 44 |
lvr = 3; // should be enacted |
| 45 |
|
| 46 |
x.handle.resume(); |
| 47 |
PRINT ("main: after resume (yield)"); |
| 48 |
|
| 49 |
/* Now we should have the co_returned value. */ |
| 50 |
y = x.handle.promise().get_value(); |
| 51 |
if ( y != 8 ) |
| 52 |
{ |
| 53 |
PRINTF ("main: wrong result (%d).", y); |
| 54 |
abort (); |
| 55 |
} |
| 56 |
|
| 57 |
y = x.handle.promise().get_v2(); |
| 58 |
if ( y != 2 ) |
| 59 |
{ |
| 60 |
PRINTF ("main: wrong result 2 (%d).", y); |
| 61 |
abort (); |
| 62 |
} |
| 63 |
|
| 64 |
y = x.handle.promise().get_v3(); |
| 65 |
if ( y != 4 ) |
| 66 |
{ |
| 67 |
PRINTF ("main: wrong result 3 (%d).", y); |
| 68 |
abort (); |
| 69 |
} |
| 70 |
|
| 71 |
if (!x.handle.done()) |
| 72 |
{ |
| 73 |
PRINT ("main: apparently not done..."); |
| 74 |
abort (); |
| 75 |
} |
| 76 |
|
| 77 |
x.handle.destroy(); |
| 78 |
x.handle = NULL; |
| 79 |
|
| 80 |
PRINT ("main: returning"); |
| 81 |
return 0; |
| 82 |
} |