| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } } |
| 3 |
|
| 4 |
#include "../coro.h" |
| 5 |
|
| 6 |
struct pt_b |
| 7 |
{ |
| 8 |
std::suspend_never final_suspend() const noexcept { return {}; } |
| 9 |
constexpr void return_void () noexcept {}; |
| 10 |
void unhandled_exception() const noexcept {} |
| 11 |
}; |
| 12 |
|
| 13 |
int called_is_op = 0; |
| 14 |
struct is |
| 15 |
{ |
| 16 |
std::suspend_never operator ()() noexcept { |
| 17 |
PRINT("call to operator IS"); |
| 18 |
called_is_op++; |
| 19 |
return {}; |
| 20 |
} |
| 21 |
}; |
| 22 |
|
| 23 |
struct pt_c : pt_b |
| 24 |
{ |
| 25 |
using handle_t = std::coroutine_handle<pt_c>; |
| 26 |
auto get_return_object() noexcept { return handle_t::from_promise(*this); } |
| 27 |
is initial_suspend; |
| 28 |
}; |
| 29 |
|
| 30 |
int called_lambda = 0; |
| 31 |
struct pt_d : pt_b |
| 32 |
{ |
| 33 |
using handle_t = std::coroutine_handle<pt_d>; |
| 34 |
auto get_return_object() noexcept { return handle_t::from_promise(*this); } |
| 35 |
static constexpr auto initial_suspend |
| 36 |
= []() noexcept { |
| 37 |
PRINT("call to lambda IS"); |
| 38 |
called_lambda++; |
| 39 |
return std::suspend_never{}; |
| 40 |
}; |
| 41 |
}; |
| 42 |
|
| 43 |
template <> |
| 44 |
struct std::coroutine_traits<pt_c::handle_t> |
| 45 |
{ using promise_type = pt_c; }; |
| 46 |
|
| 47 |
static pt_c::handle_t foo () |
| 48 |
{ |
| 49 |
co_return; |
| 50 |
} |
| 51 |
|
| 52 |
template <> |
| 53 |
struct std::coroutine_traits<pt_d::handle_t> |
| 54 |
{ using promise_type = pt_d; }; |
| 55 |
|
| 56 |
static pt_d::handle_t bar () |
| 57 |
{ |
| 58 |
co_return; |
| 59 |
} |
| 60 |
|
| 61 |
int main () |
| 62 |
{ |
| 63 |
foo (); |
| 64 |
bar (); |
| 65 |
if (called_is_op != 1 || called_lambda != 1) |
| 66 |
{ |
| 67 |
PRINT ("Failed to call one of the initial_suspend cases"); |
| 68 |
abort (); |
| 69 |
} |
| 70 |
} |