[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / PCH / coroutines.cpp
blobe5e84d01a7de19249c54b578b7a672df88bc1838
1 // Test this without pch.
2 // RUN: %clang_cc1 -include %s -verify -std=c++1z -fcoroutines-ts %s
4 // Test with pch.
5 // RUN: %clang_cc1 -std=c++1z -fcoroutines-ts -emit-pch -o %t %s
6 // RUN: %clang_cc1 -include-pch %t -verify -std=c++1z -fcoroutines-ts %s
8 #ifndef HEADER
9 #define HEADER
11 namespace std {
12 template <typename... T> struct coroutine_traits;
14 template <class Promise = void> struct coroutine_handle {
15 coroutine_handle() = default;
16 static coroutine_handle from_address(void *) noexcept;
18 template <> 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;
24 } // namespace std
26 struct suspend_always {
27 bool await_ready() noexcept;
28 void await_suspend(std::coroutine_handle<>) noexcept;
29 void await_resume() noexcept;
32 template <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;
45 template <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;
57 template <typename T>
58 void f(T x) { // checks coawait_expr and coroutine_body_stmt
59 co_yield 42; // checks coyield_expr
60 co_await x; // checks dependent_coawait
61 co_return; // checks coreturn_stmt
64 template <typename T>
65 int f2(T x) { // checks coawait_expr and coroutine_body_stmt
66 co_return x; // checks coreturn_stmt with expr
69 struct S {};
70 S operator co_await(S) { return S(); }
72 template <typename T>
73 int f3(T x) {
74 co_await x; // checks dependent_coawait with overloaded co_await operator
77 #else
79 // expected-no-diagnostics
80 void g() {
81 f(suspend_always{});
82 f2(42);
85 #endif