Author: Younan Zhang Date: 2026-01-20T09:56:04+08:00 New Revision: be40637a8a9c5fa99457856254e3dbe29b5aac58
URL: https://github.com/llvm/llvm-project/commit/be40637a8a9c5fa99457856254e3dbe29b5aac58 DIFF: https://github.com/llvm/llvm-project/commit/be40637a8a9c5fa99457856254e3dbe29b5aac58.diff LOG: [Clang] Ensure a lambda DeclContext in BuildLambdaExpr (#176319) Since 5f9630b388, we only remove the LSI after the evaluation context is popped. The TreeTransform of immediate functions may call getCurLambda, which requires both the paired LSI and the lambda DeclContext. In TransformLambdaExpr, we already switched the context, but this is not the case when parsing a lambda expression. No release note, as this is a regression from 22. Fixes https://github.com/llvm/llvm-project/issues/176045 Added: Modified: clang/lib/Sema/SemaLambda.cpp clang/test/SemaCXX/cxx2b-consteval-propagate.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp index c864a47e022bd..e1b1cd3e04946 100644 --- a/clang/lib/Sema/SemaLambda.cpp +++ b/clang/lib/Sema/SemaLambda.cpp @@ -2165,7 +2165,12 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, // set as CurContext seems more faithful to the source. TemplateOrNonTemplateCallOperatorDecl->setLexicalDeclContext(Class); - PopExpressionEvaluationContext(); + { + // TreeTransform of immediate functions may call getCurLambda, which + // requires both the paired LSI and the lambda DeclContext. + ContextRAII SavedContext(*this, CallOperator, /*NewThisContext=*/false); + PopExpressionEvaluationContext(); + } sema::AnalysisBasedWarnings::Policy WP = AnalysisWarnings.getPolicyInEffectAt(EndLoc); diff --git a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp index 6da589dcf1b25..39097d17441f7 100644 --- a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp +++ b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp @@ -629,6 +629,20 @@ void fn() { } +namespace GH176045 { + +template <int NumArgs> struct MessageFormat { + template <int N> consteval MessageFormat(const char (&)[N]) {} +}; +template <typename... Ts> void format(MessageFormat<sizeof...(Ts)>, Ts ...args); + +auto message = [] { + format(""); + format(""); +}; + +} + namespace GH109096 { consteval void undefined(); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
