Skip to content

Commit 64ffe64

Browse files
authored
[Clang] Handle sema of noexcept condition in their evaluation context. (llvm#67538)
The conditions of a noexcept and explicit specifier are full expressions. Before this patch, we would call ActOnFinishFullExpr on these in the context of the enclosing expression, which would cause the collect of odr-used variables (and subsequently capture attempts) in the wrong (enclosing) context. This was observable when parsing the noexcept specifier condition of a lambda appearing in a wider full expression odr-using variables. Fixes llvm#67492
1 parent 9744909 commit 64ffe64

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ Bug Fixes to C++ Support
359359
reference. Fixes:
360360
(`#64162 <https://github.com/llvm/llvm-project/issues/64162>`_)
361361

362+
- Clang no longer tries to capture non-odr-used variables that appear
363+
in the enclosing expression of a lambda expression with a noexcept specifier.
364+
(`#67492 <https://github.com/llvm/llvm-project/issues/67492>`_)
365+
362366
Bug Fixes to AST Handling
363367
^^^^^^^^^^^^^^^^^^^^^^^^^
364368
- Fixed an import failure of recursive friend class template.

clang/lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4120,7 +4120,11 @@ void Parser::ParseDeclarationSpecifiers(
41204120
ExprResult ExplicitExpr(static_cast<Expr *>(nullptr));
41214121
BalancedDelimiterTracker Tracker(*this, tok::l_paren);
41224122
Tracker.consumeOpen();
4123-
ExplicitExpr = ParseConstantExpression();
4123+
4124+
EnterExpressionEvaluationContext ConstantEvaluated(
4125+
Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4126+
4127+
ExplicitExpr = ParseConstantExpressionInExprEvalContext();
41244128
ConsumedEnd = Tok.getLocation();
41254129
if (ExplicitExpr.isUsable()) {
41264130
CloseParenLoc = Tok.getLocation();

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3983,7 +3983,11 @@ ExceptionSpecificationType Parser::tryParseExceptionSpecification(
39833983
// There is an argument.
39843984
BalancedDelimiterTracker T(*this, tok::l_paren);
39853985
T.consumeOpen();
3986-
NoexceptExpr = ParseConstantExpression();
3986+
3987+
EnterExpressionEvaluationContext ConstantEvaluated(
3988+
Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
3989+
NoexceptExpr = ParseConstantExpressionInExprEvalContext();
3990+
39873991
T.consumeClose();
39883992
if (!NoexceptExpr.isInvalid()) {
39893993
NoexceptExpr =

clang/test/SemaCXX/lambda-expressions.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,8 @@ void foo() {
718718
void GH48527() {
719719
auto a = []()__attribute__((b(({ return 0; })))){}; // expected-warning {{unknown attribute 'b' ignored}}
720720
}
721+
722+
void GH67492() {
723+
constexpr auto test = 42;
724+
auto lambda = (test, []() noexcept(true) {});
725+
}

0 commit comments

Comments
 (0)