| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } } |
| 3 |
|
| 4 |
// Test of forwarding a templated awaitable to co_await. |
| 5 |
|
| 6 |
#include "../coro.h" |
| 7 |
|
| 8 |
// boiler-plate for tests of codegen |
| 9 |
#include "../coro1-ret-int-yield-int.h" |
| 10 |
|
| 11 |
/* Valued with an await_transform. */ |
| 12 |
|
| 13 |
template< typename AWAITABLE > |
| 14 |
coro1 |
| 15 |
test_fwd (AWAITABLE&& awaitable) |
| 16 |
{ |
| 17 |
// the await_resume() just returns the saved int value. |
| 18 |
int a = co_await std::forward<AWAITABLE>(awaitable); |
| 19 |
// Which we co-return to the promise so that it can be |
| 20 |
// retrieved. |
| 21 |
co_return a; |
| 22 |
} |
| 23 |
|
| 24 |
int main () |
| 25 |
{ |
| 26 |
// We have an awaitable that stores the int it was constructed with. |
| 27 |
coro1::suspend_always_intprt g(15); |
| 28 |
struct coro1 g_coro = test_fwd (g); |
| 29 |
|
| 30 |
PRINT ("main: resuming g [1] (initial suspend)"); |
| 31 |
g_coro.handle.resume(); |
| 32 |
|
| 33 |
PRINT ("main: resuming g [2] co_await"); |
| 34 |
g_coro.handle.resume(); |
| 35 |
|
| 36 |
int y = g_coro.handle.promise().get_value(); |
| 37 |
if (y != 15) |
| 38 |
{ |
| 39 |
PRINTF ("main: y is wrong : %d, should be 15\n", y); |
| 40 |
abort (); |
| 41 |
} |
| 42 |
PRINT ("main: done"); |
| 43 |
return 0; |
| 44 |
} |