| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } } |
| 3 |
|
| 4 |
// Test the ability to specialize the coroutine traits to include |
| 5 |
// non-class type coroutine ramp return values. |
| 6 |
|
| 7 |
#include "../coro.h" |
| 8 |
|
| 9 |
int g_promise = -1; |
| 10 |
|
| 11 |
template<typename R, typename HandleRef, typename ...T> |
| 12 |
struct std::coroutine_traits<R, HandleRef, T...> { |
| 13 |
struct promise_type { |
| 14 |
promise_type (HandleRef h, T ...args) |
| 15 |
{ h = std::coroutine_handle<promise_type>::from_promise (*this); |
| 16 |
PRINT ("Created Promise"); |
| 17 |
g_promise = 1; |
| 18 |
} |
| 19 |
~promise_type () { PRINT ("Destroyed Promise"); g_promise = 0;} |
| 20 |
void get_return_object() {} |
| 21 |
|
| 22 |
auto initial_suspend() { |
| 23 |
return std::suspend_always{}; |
| 24 |
} |
| 25 |
auto final_suspend() noexcept { return std::suspend_never{}; } |
| 26 |
|
| 27 |
void return_void() {} |
| 28 |
void unhandled_exception() {} |
| 29 |
}; |
| 30 |
}; |
| 31 |
|
| 32 |
void |
| 33 |
my_coro (std::coroutine_handle<>& h) |
| 34 |
{ |
| 35 |
PRINT ("coro1: about to return"); |
| 36 |
co_return; |
| 37 |
} |
| 38 |
|
| 39 |
int main () |
| 40 |
{ |
| 41 |
std::coroutine_handle<> h; |
| 42 |
my_coro (h); |
| 43 |
|
| 44 |
if (h.done()) |
| 45 |
{ |
| 46 |
PRINT ("main: apparently was already done..."); |
| 47 |
abort (); |
| 48 |
} |
| 49 |
|
| 50 |
// initial suspend. |
| 51 |
h.resume (); |
| 52 |
|
| 53 |
// The coro should have self-destructed. |
| 54 |
if (g_promise) |
| 55 |
{ |
| 56 |
PRINT ("main: apparently we did not complete..."); |
| 57 |
abort (); |
| 58 |
} |
| 59 |
|
| 60 |
PRINT ("main: returning"); |
| 61 |
return 0; |
| 62 |
} |