Skip to content

Commit 85a4058

Browse files
committed
Fobbid co_await in invalid expr context
1 parent ff033d1 commit 85a4058

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

clang/lib/Sema/SemaCoroutine.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,11 @@ static bool checkSuspensionContext(Sema &S, SourceLocation Loc,
788788
// First emphasis of [expr.await]p2: must be a potentially evaluated context.
789789
// That is, 'co_await' and 'co_yield' cannot appear in subexpressions of
790790
// \c sizeof.
791-
if (S.isUnevaluatedContext()) {
791+
const auto ExprContext = S.currentEvaluationContext().ExprContext;
792+
const bool BadContext =
793+
S.isUnevaluatedContext() ||
794+
ExprContext != Sema::ExpressionEvaluationContextRecord::EK_Other;
795+
if (BadContext) {
792796
S.Diag(Loc, diag::err_coroutine_unevaluated_context) << Keyword;
793797
return false;
794798
}
@@ -798,7 +802,6 @@ static bool checkSuspensionContext(Sema &S, SourceLocation Loc,
798802
S.Diag(Loc, diag::err_coroutine_within_handler) << Keyword;
799803
return false;
800804
}
801-
802805
return true;
803806
}
804807

0 commit comments

Comments
 (0)