| 1 |
// { dg-skip-if "requires hosted libstdc++ for iostream" { ! hostedlib } } |
| 2 |
|
| 3 |
#define CASE 0 |
| 4 |
#include <coroutine> |
| 5 |
#include <iostream> |
| 6 |
|
| 7 |
struct Coroutine { |
| 8 |
|
| 9 |
struct promise_type; |
| 10 |
|
| 11 |
using handler_type = std::coroutine_handle<promise_type>; |
| 12 |
|
| 13 |
struct initial_suspend_awaiter { |
| 14 |
|
| 15 |
bool await_ready() noexcept { |
| 16 |
std::cout << "await_ready" << std::endl; |
| 17 |
return false; |
| 18 |
} |
| 19 |
|
| 20 |
void await_suspend(handler_type h) noexcept { |
| 21 |
std::cout << "await_suspend" << std::endl; |
| 22 |
} |
| 23 |
|
| 24 |
#if CASE == 0 |
| 25 |
struct await_resume_return_object { |
| 26 |
await_resume_return_object() noexcept { |
| 27 |
std::cout << "await_resume_return_object" << std::endl; |
| 28 |
} |
| 29 |
|
| 30 |
~await_resume_return_object() noexcept { |
| 31 |
std::cout << "~await_resume_return_object" << std::endl; |
| 32 |
} |
| 33 |
}; |
| 34 |
#elif CASE == 1 |
| 35 |
using await_resume_return_object = struct{}; |
| 36 |
#elif CASE == 2 |
| 37 |
using await_resume_return_object = int; |
| 38 |
#else |
| 39 |
using await_resume_return_object = void; |
| 40 |
#endif |
| 41 |
await_resume_return_object await_resume() noexcept { |
| 42 |
std::cout << "await_resume" << std::endl; |
| 43 |
#if CASE == 0 || CASE == 1 || CASE == 2 |
| 44 |
return {}; |
| 45 |
#endif |
| 46 |
} |
| 47 |
|
| 48 |
initial_suspend_awaiter() noexcept { |
| 49 |
std::cout << "initial_suspend_awaiter" << std::endl; |
| 50 |
} |
| 51 |
|
| 52 |
~initial_suspend_awaiter() noexcept { |
| 53 |
std::cout << "~initial_suspend_awaiter" << std::endl; |
| 54 |
} |
| 55 |
}; |
| 56 |
|
| 57 |
struct promise_type { |
| 58 |
void return_void() noexcept {} |
| 59 |
void unhandled_exception() noexcept { std::terminate();} |
| 60 |
initial_suspend_awaiter initial_suspend() noexcept { return {}; } |
| 61 |
std::suspend_never final_suspend() noexcept { return {}; } |
| 62 |
Coroutine get_return_object() { |
| 63 |
return Coroutine{handler_type::from_promise(*this)}; |
| 64 |
} |
| 65 |
}; |
| 66 |
|
| 67 |
handler_type handler; |
| 68 |
}; |
| 69 |
|
| 70 |
int main() { |
| 71 |
auto coro = []()->Coroutine { co_return; }(); |
| 72 |
coro.handler.resume(); |
| 73 |
} |