[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:07:06 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-coroutines
Author: None (NewSigma)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/130455.diff
1 Files Affected:
- (modified) clang/lib/Sema/SemaCoroutine.cpp (+5-2)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/130455
More information about the cfe-commits
mailing list