[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / AST / coroutine-locals-cleanup-exp-namespace.cpp
blobca5b28275e7f4e12abda8b13e65b22388bf87cc1
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcoroutines-ts -std=c++14 -fsyntax-only -ast-dump %s | FileCheck %s
3 #include "Inputs/std-coroutine-exp-namespace.h"
5 using namespace std::experimental;
7 struct Task {
8 struct promise_type {
9 Task get_return_object() noexcept {
10 return Task{coroutine_handle<promise_type>::from_promise(*this)};
13 void return_void() noexcept {}
15 struct final_awaiter {
16 bool await_ready() noexcept { return false; }
17 coroutine_handle<> await_suspend(coroutine_handle<promise_type> h) noexcept {
18 h.destroy();
19 return {};
21 void await_resume() noexcept {}
24 void unhandled_exception() noexcept {}
26 final_awaiter final_suspend() noexcept { return {}; }
28 suspend_always initial_suspend() noexcept { return {}; }
30 template <typename Awaitable>
31 auto await_transform(Awaitable &&awaitable) {
32 return awaitable.co_viaIfAsync();
36 using handle_t = coroutine_handle<promise_type>;
38 class Awaiter {
39 public:
40 explicit Awaiter(handle_t coro) noexcept;
41 Awaiter(Awaiter &&other) noexcept;
42 Awaiter(const Awaiter &) = delete;
43 ~Awaiter();
45 bool await_ready() noexcept { return false; }
46 handle_t await_suspend(coroutine_handle<> continuation) noexcept;
47 void await_resume();
49 private:
50 handle_t coro_;
53 Task(handle_t coro) noexcept : coro_(coro) {}
55 handle_t coro_;
57 Task(const Task &t) = delete;
58 Task(Task &&t) noexcept;
59 ~Task();
60 Task &operator=(Task t) noexcept;
62 Awaiter co_viaIfAsync();
65 static Task foo() {
66 co_return;
69 Task bar() {
70 auto mode = 2;
71 switch (mode) {
72 case 1:
73 co_await foo();
74 break;
75 case 2:
76 co_await foo();
77 break;
78 default:
79 break;
83 // CHECK-LABEL: FunctionDecl {{.*}} bar 'Task ()'
84 // CHECK: SwitchStmt
85 // CHECK: CaseStmt
86 // CHECK: ExprWithCleanups {{.*}} 'void'
87 // CHECK-NEXT: CoawaitExpr
88 // CHECK-NEXT: CXXBindTemporaryExpr {{.*}} 'Task':'Task' (CXXTemporary {{.*}})
89 // CHECK: MaterializeTemporaryExpr {{.*}} 'Awaiter':'Task::Awaiter'
90 // CHECK: ExprWithCleanups {{.*}} 'bool'
91 // CHECK-NEXT: CXXMemberCallExpr {{.*}} 'bool'
92 // CHECK-NEXT: MemberExpr {{.*}} .await_ready
93 // CHECK: CallExpr {{.*}} 'void'
94 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(void *)'
95 // CHECK-NEXT: DeclRefExpr {{.*}} '__builtin_coro_resume' 'void (void *)'
96 // CHECK-NEXT: ExprWithCleanups {{.*}} 'void *'
98 // CHECK: CaseStmt
99 // CHECK: ExprWithCleanups {{.*}} 'void'
100 // CHECK-NEXT: CoawaitExpr
101 // CHECK-NEXT: CXXBindTemporaryExpr {{.*}} 'Task':'Task' (CXXTemporary {{.*}})
102 // CHECK: MaterializeTemporaryExpr {{.*}} 'Awaiter':'Task::Awaiter'
103 // CHECK: ExprWithCleanups {{.*}} 'bool'
104 // CHECK-NEXT: CXXMemberCallExpr {{.*}} 'bool'
105 // CHECK-NEXT: MemberExpr {{.*}} .await_ready
106 // CHECK: CallExpr {{.*}} 'void'
107 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(void *)'
108 // CHECK-NEXT: DeclRefExpr {{.*}} '__builtin_coro_resume' 'void (void *)'
109 // CHECK-NEXT: ExprWithCleanups {{.*}} 'void *'