https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/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

>From 40ec441a9281b0de97f5ba84d79db9e2e6752568 Mon Sep 17 00:00:00 2001
From: Younan Zhang <[email protected]>
Date: Fri, 16 Jan 2026 15:41:36 +0800
Subject: [PATCH] [Clang] Ensure a lambda DeclContext in BuildLambdaExpr

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.
---
 clang/lib/Sema/SemaLambda.cpp                    |  5 ++++-
 clang/test/SemaCXX/cxx2b-consteval-propagate.cpp | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index c864a47e022bd..7a301eac6add0 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -2165,7 +2165,10 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc,
   // set as CurContext seems more faithful to the source.
   TemplateOrNonTemplateCallOperatorDecl->setLexicalDeclContext(Class);
 
-  PopExpressionEvaluationContext();
+  {
+    ContextRAII SaveContext(*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

Reply via email to