| 1 |
// { dg-additional-options "-fno-exceptions" } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for string" { ! hostedlib } } |
| 3 |
|
| 4 |
#include <coroutine> |
| 5 |
#include <string> |
| 6 |
|
| 7 |
template <typename T> |
| 8 |
struct looper { |
| 9 |
struct promise_type { |
| 10 |
auto get_return_object () { return handle_type::from_promise (*this); } |
| 11 |
auto initial_suspend () { return suspend_always_prt {}; } |
| 12 |
auto final_suspend () noexcept { return suspend_always_prt {}; } |
| 13 |
void return_value (T); |
| 14 |
void unhandled_exception (); |
| 15 |
}; |
| 16 |
|
| 17 |
using handle_type = std::coroutine_handle<promise_type>; |
| 18 |
|
| 19 |
looper (handle_type); |
| 20 |
|
| 21 |
struct suspend_always_prt { |
| 22 |
bool await_ready () noexcept; |
| 23 |
void await_suspend (handle_type) noexcept; |
| 24 |
void await_resume () noexcept; |
| 25 |
}; |
| 26 |
}; |
| 27 |
|
| 28 |
template <typename T> |
| 29 |
looper<T> |
| 30 |
with_ctorable_state (T) |
| 31 |
{ |
| 32 |
co_return T (); |
| 33 |
} |
| 34 |
|
| 35 |
auto |
| 36 |
foo () |
| 37 |
{ |
| 38 |
return with_ctorable_state<std::string>; |
| 39 |
} |