| 1 |
// { dg-additional-options "-fsyntax-only" } |
| 2 |
|
| 3 |
#if __has_include(<coroutine>) |
| 4 |
#include <coroutine> |
| 5 |
#else |
| 6 |
#include <experimental/coroutine> |
| 7 |
namespace std { |
| 8 |
using namespace std::experimental; |
| 9 |
} |
| 10 |
#endif |
| 11 |
|
| 12 |
class promise; |
| 13 |
|
| 14 |
struct finalSuspendAwaiter { |
| 15 |
int x; |
| 16 |
finalSuspendAwaiter () : x(0) { } |
| 17 |
finalSuspendAwaiter (int _x) : x(_x) { } |
| 18 |
~finalSuspendAwaiter() noexcept(false) { } |
| 19 |
// { dg-error {the expression 'finalSuspendAwaiter::~finalSuspendAwaiter' is required to be non-throwing} "" { target *-*-* } .-1 } |
| 20 |
bool await_ready() const noexcept(true) { return false; } |
| 21 |
void await_suspend(std::coroutine_handle<>) const noexcept(true) { } |
| 22 |
int await_resume() const noexcept(true) { return x; } |
| 23 |
}; |
| 24 |
|
| 25 |
struct finalSuspendObj { |
| 26 |
int x; |
| 27 |
finalSuspendObj () : x(0) { } |
| 28 |
finalSuspendObj (int _x) : x(_x) { } |
| 29 |
~finalSuspendObj () noexcept(true) {} |
| 30 |
|
| 31 |
finalSuspendAwaiter operator co_await() const & noexcept(true) { |
| 32 |
return {x}; |
| 33 |
} |
| 34 |
}; |
| 35 |
|
| 36 |
struct task { |
| 37 |
struct promise_type { |
| 38 |
task get_return_object() noexcept { return {}; } |
| 39 |
std::suspend_never initial_suspend() noexcept { return {}; } |
| 40 |
|
| 41 |
finalSuspendObj final_suspend() noexcept { return {3}; } |
| 42 |
|
| 43 |
void return_void() noexcept {} |
| 44 |
void unhandled_exception() noexcept {} |
| 45 |
}; |
| 46 |
}; |
| 47 |
|
| 48 |
// This should be ill-formed since final_suspend() is potentially throwing. |
| 49 |
task f() { |
| 50 |
co_return; |
| 51 |
} |