1 // This file contains references to sections of the Coroutines TS, which can be
2 // found at http://wg21.link/coroutines.
3 
4 // RUN: %clang_cc1 -std=c++20 -verify %s -fcxx-exceptions -fexceptions -Wunused-result
5 
6 namespace std {
7 
8 template <class Ret, typename... T>
9 struct coroutine_traits { using promise_type = typename Ret::promise_type; };
10 
11 template <class Promise = void>
12 struct coroutine_handle {
13   static coroutine_handle from_address(void *); // expected-note 2 {{must be declared with 'noexcept'}}
14 };
15 template <>
16 struct coroutine_handle<void> {
17   template <class PromiseType>
18   coroutine_handle(coroutine_handle<PromiseType>); // expected-note 2 {{must be declared with 'noexcept'}}
19 };
20 
21 struct suspend_never {
22   bool await_ready() { return true; }       // expected-note 2 {{must be declared with 'noexcept'}}
23   void await_suspend(coroutine_handle<>) {} // expected-note 2 {{must be declared with 'noexcept'}}
24   void await_resume() {}                    // expected-note 2 {{must be declared with 'noexcept'}}
25   ~suspend_never() noexcept(false);         // expected-note 2 {{must be declared with 'noexcept'}}
26 };
27 
28 struct suspend_always {
29   bool await_ready() { return false; }
30   void await_suspend(coroutine_handle<>) {}
31   void await_resume() {}
32   suspend_never operator co_await(); // expected-note 2 {{must be declared with 'noexcept'}}
33   ~suspend_always() noexcept(false); // expected-note 2 {{must be declared with 'noexcept'}}
34 };
35 
36 } // namespace std
37 
38 using namespace std;
39 
40 struct A {
41   bool await_ready();
42   void await_resume();
43   template <typename F>
44   void await_suspend(F);
45 };
46 
47 struct coro_t {
48   struct promise_type {
49     coro_t get_return_object();
50     suspend_never initial_suspend();
51     suspend_always final_suspend(); // expected-note 2 {{must be declared with 'noexcept'}}
52     void return_void();
53     static void unhandled_exception();
54   };
55 };
56 
57 coro_t f(int n) { // expected-error {{the expression 'co_await __promise.final_suspend()' is required to be non-throwing}}
58   A a{};
59   co_await a;
60 }
61 
62 template <typename T>
63 coro_t f_dep(T n) { // expected-error {{the expression 'co_await __promise.final_suspend()' is required to be non-throwing}}
64   A a{};
65   co_await a;
66 }
67 
68 void foo() {
69   f_dep<int>(5); // expected-note {{in instantiation of function template specialization 'f_dep<int>' requested here}}
70 }
71