xref: /llvm-project/clang/test/SemaCXX/thread-safety-coro.cpp (revision 6ed67ccba7e4699e9e42302f2f9b7653444258ba)
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -std=c++20 %s
2 
3 // expected-no-diagnostics
4 
5 namespace std {
6 template <typename _Result, typename...>
7 struct coroutine_traits {
8   using promise_type = typename _Result::promise_type;
9 };
10 
11 template <typename _Promise = void>
12 struct coroutine_handle;
13 
14 template <>
15 struct coroutine_handle<void> {
16   static coroutine_handle from_address(void *__a) noexcept;
17   void resume() const noexcept;
18   void destroy() const noexcept;
19 };
20 
21 template <typename _Promise>
22 struct coroutine_handle : coroutine_handle<> {};
23 
24 struct suspend_always {
25   bool await_ready() const noexcept;
26   void await_suspend(coroutine_handle<>) const noexcept;
27   void await_resume() const noexcept;
28 };
29 } // namespace std
30 
31 class Task {
32 public:
33   struct promise_type {
34   public:
35     std::suspend_always initial_suspend() noexcept;
36     std::suspend_always final_suspend() noexcept;
37 
38     Task get_return_object() noexcept;
39     void unhandled_exception() noexcept;
40     void return_value(int value) noexcept;
41 
42     std::suspend_always yield_value(int value) noexcept;
43   };
44 };
45 
Foo()46 Task Foo() noexcept {
47   // ICE'd
48   co_yield({ int frame = 0; 0; });
49   co_await({ int frame = 0; std::suspend_always(); });
50   co_return({ int frame = 0; 0; });
51 }
52