[lldb] Fix warning: 'sprintf' is deprecated in RNBSocketTest
[llvm-project.git] / clang / test / AST / coroutine-locals-cleanup.cpp
bloba7f524b0b1ac906c4a4baf02a04d2ca8cc4a108f
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -ast-dump %s | FileCheck %s
3 #include "Inputs/std-coroutine.h"
5 using namespace std;
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' (CXXTemporary {{.*}})
89 // CHECK: MaterializeTemporaryExpr {{.*}} 'Awaiter':'Task::Awaiter'
90 // CHECK: ExprWithCleanups {{.*}} 'bool'
91 // CHECK-NEXT: CXXMemberCallExpr {{.*}} 'bool'
92 // CHECK-NEXT: MemberExpr {{.*}} .await_ready
93 // CHECK: ExprWithCleanups {{.*}} 'void *'
95 // CHECK: CaseStmt
96 // CHECK: ExprWithCleanups {{.*}} 'void'
97 // CHECK-NEXT: CoawaitExpr
98 // CHECK-NEXT: CXXBindTemporaryExpr {{.*}} 'Task' (CXXTemporary {{.*}})
99 // CHECK: MaterializeTemporaryExpr {{.*}} 'Awaiter':'Task::Awaiter'
100 // CHECK: ExprWithCleanups {{.*}} 'bool'
101 // CHECK-NEXT: CXXMemberCallExpr {{.*}} 'bool'
102 // CHECK-NEXT: MemberExpr {{.*}} .await_ready
103 // CHECK: ExprWithCleanups {{.*}} 'void *'