Skip to content

Commit 1c7f7d6

Browse files
zyn0217c-rhodes
authored andcommitted
[Clang] Ensure a lambda DeclContext in BuildLambdaExpr (#176319)
Since 5f9630b, 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 #176045 (cherry picked from commit be40637)
1 parent 95b6745 commit 1c7f7d6

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

clang/lib/Sema/SemaLambda.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,12 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc,
21652165
// set as CurContext seems more faithful to the source.
21662166
TemplateOrNonTemplateCallOperatorDecl->setLexicalDeclContext(Class);
21672167

2168-
PopExpressionEvaluationContext();
2168+
{
2169+
// TreeTransform of immediate functions may call getCurLambda, which
2170+
// requires both the paired LSI and the lambda DeclContext.
2171+
ContextRAII SavedContext(*this, CallOperator, /*NewThisContext=*/false);
2172+
PopExpressionEvaluationContext();
2173+
}
21692174

21702175
sema::AnalysisBasedWarnings::Policy WP =
21712176
AnalysisWarnings.getPolicyInEffectAt(EndLoc);

clang/test/SemaCXX/cxx2b-consteval-propagate.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,20 @@ void fn() {
629629

630630
}
631631

632+
namespace GH176045 {
633+
634+
template <int NumArgs> struct MessageFormat {
635+
template <int N> consteval MessageFormat(const char (&)[N]) {}
636+
};
637+
template <typename... Ts> void format(MessageFormat<sizeof...(Ts)>, Ts ...args);
638+
639+
auto message = [] {
640+
format("");
641+
format("");
642+
};
643+
644+
}
645+
632646

633647
namespace GH109096 {
634648
consteval void undefined();

0 commit comments

Comments
 (0)