1 // This file contains references to sections of the Coroutines TS, which can be
2 // found at http://wg21.link/coroutines.
4 // RUN: %clang_cc1 -std=c++20 -verify %s -fcxx-exceptions -fexceptions -Wunused-result
8 template <class Ret
, typename
... T
>
9 struct coroutine_traits
{ using promise_type
= typename
Ret::promise_type
; };
11 template <class Promise
= void>
12 struct coroutine_handle
{
13 static coroutine_handle
from_address(void *);
14 void *address() const noexcept
;
17 struct coroutine_handle
<void> {
18 template <class PromiseType
>
19 coroutine_handle(coroutine_handle
<PromiseType
>);
20 void *address() const noexcept
;
23 struct suspend_always
{
24 bool await_ready() { return false; } // expected-note 2 {{must be declared with 'noexcept'}}
25 void await_suspend(coroutine_handle
<>) {} // expected-note 2 {{must be declared with 'noexcept'}}
26 void await_resume() {} // expected-note 2 {{must be declared with 'noexcept'}}
27 ~suspend_always() noexcept(false); // expected-note 2 {{must be declared with 'noexcept'}}
38 void await_suspend(F
);
43 coro_t
get_return_object();
44 suspend_always
initial_suspend();
45 suspend_always
final_suspend(); // expected-note 2 {{must be declared with 'noexcept'}}
47 static void unhandled_exception();
51 coro_t
f(int n
) { // expected-error {{the expression 'co_await __promise.final_suspend()' is required to be non-throwing}}
57 coro_t
f_dep(T n
) { // expected-error {{the expression 'co_await __promise.final_suspend()' is required to be non-throwing}}
63 f_dep
<int>(5); // expected-note {{in instantiation of function template specialization 'f_dep<int>' requested here}}
66 struct PositiveFinalSuspend
{
67 bool await_ready() noexcept
;
68 coroutine_handle
<> await_suspend(coroutine_handle
<>) noexcept
;
69 void await_resume() noexcept
;
74 correct_coro
get_return_object();
75 suspend_always
initial_suspend();
76 PositiveFinalSuspend
final_suspend() noexcept
;
78 static void unhandled_exception();
82 correct_coro
f2(int n
) {
86 struct NegativeFinalSuspend
{
87 bool await_ready() noexcept
;
88 coroutine_handle
<> await_suspend(coroutine_handle
<>) noexcept
;
89 void await_resume() noexcept
;
90 ~NegativeFinalSuspend() noexcept(false); // expected-note {{must be declared with 'noexcept'}}
93 struct incorrect_coro
{
95 incorrect_coro
get_return_object();
96 suspend_always
initial_suspend();
97 NegativeFinalSuspend
final_suspend() noexcept
;
99 static void unhandled_exception();
103 incorrect_coro
f3(int n
) { // expected-error {{the expression 'co_await __promise.final_suspend()' is required to be non-throwing}}