summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/coroutines.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2015-10-27 06:02:45 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2015-10-27 06:02:45 +0000
commit9f690bd80bb67d483df2b9e15261e548f8b3a474 (patch)
treec4d74a57ede2212275c7594e815508082249bb93 /clang/test/SemaCXX/coroutines.cpp
parentd5510d1e5c2d0e4d18389f1f0c1f649cecea5d3a (diff)
downloadbcm5719-llvm-9f690bd80bb67d483df2b9e15261e548f8b3a474.tar.gz
bcm5719-llvm-9f690bd80bb67d483df2b9e15261e548f8b3a474.zip
[coroutines] Creation of promise object, lookup of operator co_await, building
of await_* calls, and AST representation for same. llvm-svn: 251387
Diffstat (limited to 'clang/test/SemaCXX/coroutines.cpp')
-rw-r--r--clang/test/SemaCXX/coroutines.cpp88
1 files changed, 72 insertions, 16 deletions
diff --git a/clang/test/SemaCXX/coroutines.cpp b/clang/test/SemaCXX/coroutines.cpp
index ae24dd2979f..3e18187295d 100644
--- a/clang/test/SemaCXX/coroutines.cpp
+++ b/clang/test/SemaCXX/coroutines.cpp
@@ -1,37 +1,68 @@
// RUN: %clang_cc1 -std=c++14 -fcoroutines -verify %s
+struct awaitable {
+ bool await_ready();
+ void await_suspend(); // FIXME: coroutine_handle
+ void await_resume();
+} a;
+
+void no_coroutine_traits() {
+ co_await a; // expected-error {{need to include <coroutine>}}
+}
+
+namespace std {
+ template<typename ...T> struct coroutine_traits; // expected-note {{declared here}}
+};
+
+void no_specialization() {
+ co_await a; // expected-error {{implicit instantiation of undefined template 'std::coroutine_traits<void>'}}
+}
+
+template<typename ...T> struct std::coroutine_traits<int, T...> {};
+
+int no_promise_type() {
+ co_await a; // expected-error {{this function cannot be a coroutine: 'coroutine_traits<int>' has no member named 'promise_type'}}
+}
+
+struct promise; // expected-note {{forward declaration}}
+template<typename ...T> struct std::coroutine_traits<void, T...> { using promise_type = promise; };
+
+ // FIXME: This diagnostic is terrible.
+void undefined_promise() { // expected-error {{variable has incomplete type 'promise_type'}}
+ co_await a;
+}
+
+struct promise {};
+
void mixed_yield() {
- // FIXME: diagnose
- co_yield 0;
- return;
+ co_yield 0; // expected-note {{use of 'co_yield'}}
+ return; // expected-error {{not allowed in coroutine}}
}
void mixed_await() {
- // FIXME: diagnose
- co_await 0;
- return;
+ co_await a; // expected-note {{use of 'co_await'}}
+ return; // expected-error {{not allowed in coroutine}}
}
void only_coreturn() {
- // FIXME: diagnose
- co_return;
+ co_return; // expected-warning {{'co_return' used in a function that uses neither 'co_await' nor 'co_yield'}}
}
void mixed_coreturn(bool b) {
- // FIXME: diagnose
if (b)
- co_return;
+ // expected-warning@+1 {{'co_return' used in a function that uses neither}}
+ co_return; // expected-note {{use of 'co_return'}}
else
- return;
+ return; // expected-error {{not allowed in coroutine}}
}
struct CtorDtor {
CtorDtor() {
co_yield 0; // expected-error {{'co_yield' cannot be used in a constructor}}
}
- CtorDtor(int n) {
+ CtorDtor(awaitable a) {
// The spec doesn't say this is ill-formed, but it must be.
- co_await n; // expected-error {{'co_await' cannot be used in a constructor}}
+ co_await a; // expected-error {{'co_await' cannot be used in a constructor}}
}
~CtorDtor() {
co_return 0; // expected-error {{'co_return' cannot be used in a destructor}}
@@ -42,10 +73,35 @@ struct CtorDtor {
}
};
-constexpr void constexpr_coroutine() {
- co_yield 0; // expected-error {{'co_yield' cannot be used in a constexpr function}}
+constexpr void constexpr_coroutine() { // expected-error {{never produces a constant expression}}
+ co_yield 0; // expected-error {{'co_yield' cannot be used in a constexpr function}} expected-note {{subexpression}}
}
void varargs_coroutine(const char *, ...) {
- co_await 0; // expected-error {{'co_await' cannot be used in a varargs function}}
+ co_await a; // expected-error {{'co_await' cannot be used in a varargs function}}
+}
+
+struct outer {};
+
+namespace dependent_operator_co_await_lookup {
+ template<typename T> void await_template(T t) {
+ // no unqualified lookup results
+ co_await t; // expected-error {{no member named 'await_ready' in 'dependent_operator_co_await_lookup::not_awaitable'}}
+ // expected-error@-1 {{call to function 'operator co_await' that is neither visible in the template definition nor found by argument-dependent lookup}}
+ };
+ template void await_template(awaitable);
+
+ struct indirectly_awaitable { indirectly_awaitable(outer); };
+ awaitable operator co_await(indirectly_awaitable); // expected-note {{should be declared prior to}}
+ template void await_template(indirectly_awaitable);
+
+ struct not_awaitable {};
+ template void await_template(not_awaitable); // expected-note {{instantiation}}
+
+ template<typename T> void await_template_2(T t) {
+ // one unqualified lookup result
+ co_await t;
+ };
+ template void await_template(outer); // expected-note {{instantiation}}
+ template void await_template_2(outer);
}
OpenPOWER on IntegriCloud