[clang] Fobbid co_await and co_yield in invalid expr context (PR #130455)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 8 19:06:09 PST 2025
https://github.com/NewSigma created https://github.com/llvm/llvm-project/pull/130455
Fix #78426
C++26 introduced braced initializer lists as template arguments. However, such contexts should be considered invalid for co_await and co_yield. This commit explicitly rules out the possibility of using these exprs in template arguments.
>From 85a40587375533ac8fcd842395c923895c5debaf Mon Sep 17 00:00:00 2001
From: NewSigma <NewSigma at 163.com>
Date: Sun, 9 Mar 2025 10:27:24 +0800
Subject: [PATCH] Fobbid co_await in invalid expr context
---
clang/lib/Sema/SemaCoroutine.cpp | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index 0e4f3b20c78cd..53536b0d14037 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -788,7 +788,11 @@ static bool checkSuspensionContext(Sema &S, SourceLocation Loc,
// First emphasis of [expr.await]p2: must be a potentially evaluated context.
// That is, 'co_await' and 'co_yield' cannot appear in subexpressions of
// \c sizeof.
- if (S.isUnevaluatedContext()) {
+ const auto ExprContext = S.currentEvaluationContext().ExprContext;
+ const bool BadContext =
+ S.isUnevaluatedContext() ||
+ ExprContext != Sema::ExpressionEvaluationContextRecord::EK_Other;
+ if (BadContext) {
S.Diag(Loc, diag::err_coroutine_unevaluated_context) << Keyword;
return false;
}
@@ -798,7 +802,6 @@ static bool checkSuspensionContext(Sema &S, SourceLocation Loc,
S.Diag(Loc, diag::err_coroutine_within_handler) << Keyword;
return false;
}
-
return true;
}
More information about the cfe-commits
mailing list