| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } } |
| 3 |
|
| 4 |
// Test that we can manage a constructed param reference |
| 5 |
|
| 6 |
#include "../coro.h" |
| 7 |
|
| 8 |
// boiler-plate for tests of codegen |
| 9 |
#include "../coro1-ret-int-yield-int.h" |
| 10 |
|
| 11 |
// Require a ctor. |
| 12 |
struct nontriv { |
| 13 |
int a, b, c; |
| 14 |
nontriv (int _a, int _b, int _c) : a(_a), b(_b), c(_c) {} |
| 15 |
virtual int getA () { return a; } |
| 16 |
}; |
| 17 |
|
| 18 |
struct coro1 |
| 19 |
f (nontriv &t) noexcept |
| 20 |
{ |
| 21 |
if (t.a > 30) |
| 22 |
{ |
| 23 |
PRINTF ("coro1: about to return %d", t.b); |
| 24 |
co_return t.b; |
| 25 |
} |
| 26 |
else if (t.a > 20) |
| 27 |
{ |
| 28 |
PRINTF ("coro1: about to co-return %d", t.c); |
| 29 |
co_return t.c; |
| 30 |
} |
| 31 |
else |
| 32 |
{ |
| 33 |
PRINT ("coro1: about to return 0"); |
| 34 |
co_return 0; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
int main () |
| 39 |
{ |
| 40 |
PRINT ("main: create coro1"); |
| 41 |
nontriv test (25, 6174, 42); |
| 42 |
struct coro1 x = f (test); |
| 43 |
PRINT ("main: got coro1 - resuming"); |
| 44 |
if (x.handle.done()) |
| 45 |
abort(); |
| 46 |
x.handle.resume(); |
| 47 |
PRINT ("main: after resume"); |
| 48 |
int y = x.handle.promise().get_value(); |
| 49 |
if ( y != 42 ) |
| 50 |
abort (); |
| 51 |
if (!x.handle.done()) |
| 52 |
{ |
| 53 |
PRINT ("main: apparently not done..."); |
| 54 |
abort (); |
| 55 |
} |
| 56 |
PRINT ("main: returning"); |
| 57 |
return 0; |
| 58 |
} |