| 1 |
// RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -verify |
| 2 |
#include "Inputs/std-coroutine.h" |
| 3 |
|
| 4 |
struct MyTask{ |
| 5 |
struct promise_type { |
| 6 |
MyTask get_return_object(); |
| 7 |
std::suspend_always initial_suspend() { return {}; } |
| 8 |
|
| 9 |
void unhandled_exception(); |
| 10 |
void return_void(); |
| 11 |
auto final_suspend() noexcept { |
| 12 |
struct Awaiter { |
| 13 |
bool await_ready() noexcept { return false; } |
| 14 |
std::coroutine_handle<promise_type> await_suspend(std::coroutine_handle<promise_type> h) noexcept; |
| 15 |
void await_resume() noexcept; |
| 16 |
}; |
| 17 |
|
| 18 |
return Awaiter{}; |
| 19 |
} |
| 20 |
|
| 21 |
// The coroutine to resume when we're done. |
| 22 |
std::coroutine_handle<promise_type> resume_when_done; |
| 23 |
}; |
| 24 |
}; |
| 25 |
|
| 26 |
MyTask DoSomething() { |
| 27 |
static_assert(__is_same(void, decltype(co_await 0))); // expected-error {{'co_await' cannot be used in an unevaluated context}} |
| 28 |
co_return; |
| 29 |
} |
| 30 |
|
| 31 |
MyTask DoAnotherthing() { |
| 32 |
static_assert(__is_same(void, decltype(co_yield 0))); // expected-error {{'co_yield' cannot be used in an unevaluated context}} |
| 33 |
co_return; |
| 34 |
} |
| 35 |
|
| 36 |
template<class> |
| 37 |
struct Task {}; |
| 38 |
|
| 39 |
void BracedInitListCXX26() { |
| 40 |
[]() -> Task<{ co_await 1 }> {}; // expected-error {{'co_await' cannot be used in an unevaluated context}} |
| 41 |
[]() -> Task<{ co_yield 1 }> {}; // expected-error {{'co_yield' cannot be used in an unevaluated context}} |
| 42 |
} |