summaryrefslogtreecommitdiffstats
path: root/test/SemaCXX/coroutines.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaCXX/coroutines.cpp')
-rw-r--r--test/SemaCXX/coroutines.cpp86
1 files changed, 68 insertions, 18 deletions
diff --git a/test/SemaCXX/coroutines.cpp b/test/SemaCXX/coroutines.cpp
index d58cedf414..99964ef6bc 100644
--- a/test/SemaCXX/coroutines.cpp
+++ b/test/SemaCXX/coroutines.cpp
@@ -314,13 +314,23 @@ struct CtorDtor {
}
};
+namespace std { class type_info; }
+
void unevaluated() {
- decltype(co_await a); // expected-error {{cannot be used in an unevaluated context}}
- sizeof(co_await a); // expected-error {{cannot be used in an unevaluated context}}
- typeid(co_await a); // expected-error {{cannot be used in an unevaluated context}}
- decltype(co_yield a); // expected-error {{cannot be used in an unevaluated context}}
- sizeof(co_yield a); // expected-error {{cannot be used in an unevaluated context}}
- typeid(co_yield a); // expected-error {{cannot be used in an unevaluated context}}
+ decltype(co_await a); // expected-error {{'co_await' cannot be used in an unevaluated context}}
+ // expected-warning@-1 {{declaration does not declare anything}}
+ sizeof(co_await a); // expected-error {{'co_await' cannot be used in an unevaluated context}}
+ // expected-error@-1 {{invalid application of 'sizeof' to an incomplete type 'void'}}
+ typeid(co_await a); // expected-error {{'co_await' cannot be used in an unevaluated context}}
+ // expected-warning@-1 {{expression with side effects has no effect in an unevaluated context}}
+ // expected-warning@-2 {{expression result unused}}
+ decltype(co_yield 1); // expected-error {{'co_yield' cannot be used in an unevaluated context}}
+ // expected-warning@-1 {{declaration does not declare anything}}
+ sizeof(co_yield 2); // expected-error {{'co_yield' cannot be used in an unevaluated context}}
+ // expected-error@-1 {{invalid application of 'sizeof' to an incomplete type 'void'}}
+ typeid(co_yield 3); // expected-error {{'co_yield' cannot be used in an unevaluated context}}
+ // expected-warning@-1 {{expression with side effects has no effect in an unevaluated context}}
+ // expected-warning@-2 {{expression result unused}}
}
// [expr.await]p2: "An await-expression shall not appear in a default argument."
@@ -328,6 +338,47 @@ void unevaluated() {
// not allowed. A user may not understand that this is "outside a function."
void default_argument(int arg = co_await 0) {} // expected-error {{'co_await' cannot be used outside a function}}
+void await_in_catch_coroutine() {
+ try {
+ } catch (...) { // FIXME: Emit a note diagnostic pointing out the try handler on this line.
+ []() -> void { co_await a; }(); // OK
+ co_await a; // expected-error {{'co_await' cannot be used in the handler of a try block}}
+ }
+}
+
+void await_nested_in_catch_coroutine() {
+ try {
+ } catch (...) { // FIXME: Emit a note diagnostic pointing out the try handler on this line.
+ try {
+ co_await a; // expected-error {{'co_await' cannot be used in the handler of a try block}}
+ []() -> void { co_await a; }(); // OK
+ } catch (...) {
+ co_return 123;
+ }
+ }
+}
+
+void await_in_lambda_in_catch_coroutine() {
+ try {
+ } catch (...) {
+ []() -> void { co_await a; }(); // OK
+ }
+}
+
+void yield_in_catch_coroutine() {
+ try {
+ } catch (...) {
+ co_yield 1; // expected-error {{'co_yield' cannot be used in the handler of a try block}}
+ }
+}
+
+void return_in_catch_coroutine() {
+ try {
+ } catch (...) {
+ co_return 123; // OK
+ }
+}
+
constexpr auto constexpr_deduced_return_coroutine() {
co_yield 0; // expected-error {{'co_yield' cannot be used in a constexpr function}}
// expected-error@-1 {{'co_yield' cannot be used in a function with a deduced return type}}
@@ -598,26 +649,26 @@ template coro<bad_promise_7> no_unhandled_exception_dependent(bad_promise_7); //
struct bad_promise_base {
private:
- void return_void();
+ void return_void(); // expected-note 2 {{declared private here}}
};
struct bad_promise_8 : bad_promise_base {
coro<bad_promise_8> get_return_object();
suspend_always initial_suspend();
suspend_always final_suspend();
- void unhandled_exception() __attribute__((unavailable)); // expected-note 2 {{made unavailable}}
- void unhandled_exception() const; // expected-note 2 {{candidate}}
- void unhandled_exception(void *) const; // expected-note 2 {{requires 1 argument, but 0 were provided}}
+ void unhandled_exception() __attribute__((unavailable)); // expected-note 2 {{marked unavailable here}}
+ void unhandled_exception() const;
+ void unhandled_exception(void *) const;
};
coro<bad_promise_8> calls_unhandled_exception() {
- // expected-error@-1 {{call to unavailable member function 'unhandled_exception'}}
- // FIXME: also warn about private 'return_void' here. Even though building
- // the call to unhandled_exception has already failed.
+ // expected-error@-1 {{'unhandled_exception' is unavailable}}
+ // expected-error@-2 {{'return_void' is a private member}}
co_await a;
}
template <class T>
coro<T> calls_unhandled_exception_dependent(T) {
- // expected-error@-1 {{call to unavailable member function 'unhandled_exception'}}
+ // expected-error@-1 {{'unhandled_exception' is unavailable}}
+ // expected-error@-2 {{'return_void' is a private member}}
co_await a;
}
template coro<bad_promise_8> calls_unhandled_exception_dependent(bad_promise_8); // expected-note {{in instantiation}}
@@ -626,14 +677,13 @@ struct bad_promise_9 {
coro<bad_promise_9> get_return_object();
suspend_always initial_suspend();
suspend_always final_suspend();
- void await_transform(void *); // expected-note {{candidate}}
- awaitable await_transform(int) __attribute__((unavailable)); // expected-note {{explicitly made unavailable}}
+ void await_transform(void *);
+ awaitable await_transform(int) __attribute__((unavailable)); // expected-note {{explicitly marked unavailable}}
void return_void();
void unhandled_exception();
};
coro<bad_promise_9> calls_await_transform() {
- co_await 42; // expected-error {{call to unavailable member function 'await_transform'}}
- // expected-note@-1 {{call to 'await_transform' implicitly required by 'co_await' here}}
+ co_await 42; // expected-error {{'await_transform' is unavailable}}
}
struct bad_promise_10 {