]> granicus.if.org Git - clang/commitdiff
[Coroutines] Fix assertion about uncorrected typos in co_await/co_yield/co_return...
authorEric Fiselier <eric@efcs.ca>
Thu, 29 Sep 2016 21:47:39 +0000 (21:47 +0000)
committerEric Fiselier <eric@efcs.ca>
Thu, 29 Sep 2016 21:47:39 +0000 (21:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282792 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaCoroutine.cpp
test/SemaCXX/coroutines.cpp

index c8715fff41596a5a51df84b3a3d9c807eb69a429..514303608869e9ee6942e3f71e3faade7c0de0ca 100644 (file)
@@ -213,6 +213,11 @@ static ReadySuspendResumeResult buildCoawaitCalls(Sema &S, SourceLocation Loc,
 }
 
 ExprResult Sema::ActOnCoawaitExpr(Scope *S, SourceLocation Loc, Expr *E) {
+  auto *Coroutine = checkCoroutineContext(*this, Loc, "co_await");
+  if (!Coroutine) {
+    CorrectDelayedTyposInExpr(E);
+    return ExprError();
+  }
   if (E->getType()->isPlaceholderType()) {
     ExprResult R = CheckPlaceholderExpr(E);
     if (R.isInvalid()) return ExprError();
@@ -222,6 +227,7 @@ ExprResult Sema::ActOnCoawaitExpr(Scope *S, SourceLocation Loc, Expr *E) {
   ExprResult Awaitable = buildOperatorCoawaitCall(*this, S, Loc, E);
   if (Awaitable.isInvalid())
     return ExprError();
+
   return BuildCoawaitExpr(Loc, Awaitable.get());
 }
 ExprResult Sema::BuildCoawaitExpr(SourceLocation Loc, Expr *E) {
@@ -275,8 +281,10 @@ static ExprResult buildPromiseCall(Sema &S, FunctionScopeInfo *Coroutine,
 
 ExprResult Sema::ActOnCoyieldExpr(Scope *S, SourceLocation Loc, Expr *E) {
   auto *Coroutine = checkCoroutineContext(*this, Loc, "co_yield");
-  if (!Coroutine)
+  if (!Coroutine) {
+    CorrectDelayedTyposInExpr(E);
     return ExprError();
+  }
 
   // Build yield_value call.
   ExprResult Awaitable =
@@ -325,6 +333,11 @@ ExprResult Sema::BuildCoyieldExpr(SourceLocation Loc, Expr *E) {
 }
 
 StmtResult Sema::ActOnCoreturnStmt(SourceLocation Loc, Expr *E) {
+  auto *Coroutine = checkCoroutineContext(*this, Loc, "co_return");
+  if (!Coroutine) {
+    CorrectDelayedTyposInExpr(E);
+    return StmtError();
+  }
   return BuildCoreturnStmt(Loc, E);
 }
 StmtResult Sema::BuildCoreturnStmt(SourceLocation Loc, Expr *E) {
index e82cb62f12d42b0cada011bcd3f2d29afcde5020..d375e9eddb3770413371332b330b10727ebbc83b 100644 (file)
@@ -1,5 +1,22 @@
 // RUN: %clang_cc1 -std=c++14 -fcoroutines -verify %s
 
+void no_coroutine_traits_bad_arg_await() {
+  co_await a; // expected-error {{include <coroutine>}}
+  // expected-error@-1 {{use of undeclared identifier 'a'}}
+}
+
+void no_coroutine_traits_bad_arg_yield() {
+  co_yield a; // expected-error {{include <coroutine>}}
+  // expected-error@-1 {{use of undeclared identifier 'a'}}
+}
+
+
+void no_coroutine_traits_bad_arg_return() {
+  co_return a; // expected-error {{include <coroutine>}}
+  // expected-error@-1 {{use of undeclared identifier 'a'}}
+}
+
+
 struct awaitable {
   bool await_ready();
   void await_suspend(); // FIXME: coroutine_handle