| 1 |
// { dg-do run } |
| 2 |
// { dg-output "coroutine name: MyFoo" } |
| 3 |
// { dg-skip-if "requires hosted libstdc++ for cstdio" { ! hostedlib } } |
| 4 |
#include <coroutine> |
| 5 |
#include <cstdio> |
| 6 |
|
| 7 |
struct pt |
| 8 |
{ |
| 9 |
using handle_t = std::coroutine_handle<pt>; |
| 10 |
auto get_return_object() noexcept { return handle_t::from_promise(*this); } |
| 11 |
|
| 12 |
std::suspend_never initial_suspend () const noexcept { return {}; } |
| 13 |
std::suspend_never final_suspend () const noexcept { return {}; } |
| 14 |
void return_void() const noexcept {} |
| 15 |
void unhandled_exception() const noexcept {} |
| 16 |
}; |
| 17 |
|
| 18 |
template <> struct std::coroutine_traits<pt::handle_t> |
| 19 |
{ using promise_type = pt; }; |
| 20 |
|
| 21 |
static pt::handle_t MyFoo () |
| 22 |
{ |
| 23 |
printf ("coroutine name: %s\n", __builtin_FUNCTION()); |
| 24 |
co_return; |
| 25 |
} |
| 26 |
|
| 27 |
int main() |
| 28 |
{ |
| 29 |
MyFoo (); |
| 30 |
} |