Author: cor3ntin Date: 2023-09-28T08:25:30+02:00 New Revision: 64ffe64d2dee03888ac6765c185b78d79bce3eca
URL: https://github.com/llvm/llvm-project/commit/64ffe64d2dee03888ac6765c185b78d79bce3eca DIFF: https://github.com/llvm/llvm-project/commit/64ffe64d2dee03888ac6765c185b78d79bce3eca.diff LOG: [Clang] Handle sema of noexcept condition in their evaluation context. (#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 #67492 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Parse/ParseDecl.cpp clang/lib/Parse/ParseDeclCXX.cpp clang/test/SemaCXX/lambda-expressions.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 68172d5317a13ba..f314c9c72fa28b7 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -359,6 +359,10 @@ Bug Fixes to C++ Support reference. Fixes: (`#64162 <https://github.com/llvm/llvm-project/issues/64162>`_) +- Clang no longer tries to capture non-odr-used variables that appear + in the enclosing expression of a lambda expression with a noexcept specifier. + (`#67492 <https://github.com/llvm/llvm-project/issues/67492>`_) + Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed an import failure of recursive friend class template. diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 748b9d53c9f5b33..9bda4ec7d59bbf8 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4120,7 +4120,11 @@ void Parser::ParseDeclarationSpecifiers( ExprResult ExplicitExpr(static_cast<Expr *>(nullptr)); BalancedDelimiterTracker Tracker(*this, tok::l_paren); Tracker.consumeOpen(); - ExplicitExpr = ParseConstantExpression(); + + EnterExpressionEvaluationContext ConstantEvaluated( + Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); + + ExplicitExpr = ParseConstantExpressionInExprEvalContext(); ConsumedEnd = Tok.getLocation(); if (ExplicitExpr.isUsable()) { CloseParenLoc = Tok.getLocation(); diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 5a6b5efbf6c1223..2c37ba800372346 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -3983,7 +3983,11 @@ ExceptionSpecificationType Parser::tryParseExceptionSpecification( // There is an argument. BalancedDelimiterTracker T(*this, tok::l_paren); T.consumeOpen(); - NoexceptExpr = ParseConstantExpression(); + + EnterExpressionEvaluationContext ConstantEvaluated( + Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); + NoexceptExpr = ParseConstantExpressionInExprEvalContext(); + T.consumeClose(); if (!NoexceptExpr.isInvalid()) { NoexceptExpr = diff --git a/clang/test/SemaCXX/lambda-expressions.cpp b/clang/test/SemaCXX/lambda-expressions.cpp index 0c9e8584e653473..9cf81a0a195a573 100644 --- a/clang/test/SemaCXX/lambda-expressions.cpp +++ b/clang/test/SemaCXX/lambda-expressions.cpp @@ -718,3 +718,8 @@ void foo() { void GH48527() { auto a = []()__attribute__((b(({ return 0; })))){}; // expected-warning {{unknown attribute 'b' ignored}} } + +void GH67492() { + constexpr auto test = 42; + auto lambda = (test, []() noexcept(true) {}); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits