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++14 -fcoroutines-ts -verify %s -fcxx-exceptions -fexceptions -Wunused-result 5 6 namespace std { 7 namespace experimental { 8 9 template <class Ret, typename... T> 10 struct coroutine_traits { using promise_type = typename Ret::promise_type; }; 11 12 template <class Promise = void> 13 struct coroutine_handle { 14 static coroutine_handle from_address(void *); // expected-note 2 {{must be declared with 'noexcept'}} 15 }; 16 template <> 17 struct coroutine_handle<void> { 18 template <class PromiseType> 19 coroutine_handle(coroutine_handle<PromiseType>); // expected-note 2 {{must be declared with 'noexcept'}} 20 }; 21 22 struct suspend_never { await_readystd::experimental::suspend_never23 bool await_ready() { return true; } // expected-note 2 {{must be declared with 'noexcept'}} await_suspendstd::experimental::suspend_never24 void await_suspend(coroutine_handle<>) {} // expected-note 2 {{must be declared with 'noexcept'}} await_resumestd::experimental::suspend_never25 void await_resume() {} // expected-note 2 {{must be declared with 'noexcept'}} 26 ~suspend_never() noexcept(false); // expected-note 2 {{must be declared with 'noexcept'}} 27 }; 28 29 struct suspend_always { await_readystd::experimental::suspend_always30 bool await_ready() { return false; } await_suspendstd::experimental::suspend_always31 void await_suspend(coroutine_handle<>) {} await_resumestd::experimental::suspend_always32 void await_resume() {} 33 suspend_never operator co_await(); // expected-note 2 {{must be declared with 'noexcept'}} 34 ~suspend_always() noexcept(false); // expected-note 2 {{must be declared with 'noexcept'}} 35 }; 36 37 } // namespace experimental 38 } // namespace std 39 40 using namespace std::experimental; 41 42 struct A { 43 bool await_ready(); 44 void await_resume(); 45 template <typename F> 46 void await_suspend(F); 47 }; 48 49 struct coro_t { 50 struct promise_type { 51 coro_t get_return_object(); 52 suspend_never initial_suspend(); 53 suspend_always final_suspend(); // expected-note 2 {{must be declared with 'noexcept'}} 54 void return_void(); 55 static void unhandled_exception(); 56 }; 57 }; 58 f(int n)59coro_t f(int n) { // expected-error {{the expression 'co_await __promise.final_suspend()' is required to be non-throwing}} 60 A a{}; 61 co_await a; 62 } 63 64 template <typename T> f_dep(T n)65coro_t f_dep(T n) { // expected-error {{the expression 'co_await __promise.final_suspend()' is required to be non-throwing}} 66 A a{}; 67 co_await a; 68 } 69 foo()70void foo() { 71 f_dep<int>(5); // expected-note {{in instantiation of function template specialization 'f_dep<int>' requested here}} 72 } 73