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