86 lines · cpp
1// Test this without pch.2// RUN: %clang_cc1 -include %s -verify -std=c++20 %s3 4// Test with pch.5// RUN: %clang_cc1 -std=c++20 -emit-pch -o %t %s6// RUN: %clang_cc1 -include-pch %t -verify -std=c++20 %s7 8#ifndef HEADER9#define HEADER10 11namespace std {12template <typename... T> struct coroutine_traits;13 14template <class Promise = void> struct coroutine_handle {15 coroutine_handle() = default;16 static coroutine_handle from_address(void *) noexcept;17};18template <> struct coroutine_handle<void> {19 static coroutine_handle from_address(void *) noexcept;20 coroutine_handle() = default;21 template <class PromiseType>22 coroutine_handle(coroutine_handle<PromiseType>) noexcept;23};24} // namespace std25 26struct suspend_always {27 bool await_ready() noexcept;28 void await_suspend(std::coroutine_handle<>) noexcept;29 void await_resume() noexcept;30};31 32template <typename... Args> struct std::coroutine_traits<void, Args...> {33 struct promise_type {34 void get_return_object() noexcept;35 suspend_always initial_suspend() noexcept;36 suspend_always final_suspend() noexcept;37 void return_void() noexcept;38 suspend_always yield_value(int) noexcept;39 promise_type();40 ~promise_type() noexcept;41 void unhandled_exception() noexcept;42 };43};44 45template <typename... Args> struct std::coroutine_traits<int, Args...> {46 struct promise_type {47 int get_return_object() noexcept;48 suspend_always initial_suspend() noexcept;49 suspend_always final_suspend() noexcept;50 void return_value(int) noexcept;51 promise_type();52 ~promise_type() noexcept;53 void unhandled_exception() noexcept;54 };55};56 57template <typename T>58void f(T x) { // checks coawait_expr and coroutine_body_stmt59 co_yield 42; // checks coyield_expr60 co_await x; // checks dependent_coawait61 co_return; // checks coreturn_stmt62}63 64template <typename T>65int f2(T x) { // checks coawait_expr and coroutine_body_stmt66 co_return x; // checks coreturn_stmt with expr67}68 69struct S {};70S operator co_await(S) { return S(); }71 72template <typename T>73int f3(T x) {74 co_await x; // checks dependent_coawait with overloaded co_await operator75}76 77#else78 79// expected-no-diagnostics80void g() {81 f(suspend_always{});82 f2(42);83}84 85#endif86