https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/140859
Lambda bodies should not be treated as subexpressions of the enclosing scope. >From f5e126d72bf6516ed36cfddce862af858968310f Mon Sep 17 00:00:00 2001 From: Corentin Jabot <corentinja...@gmail.com> Date: Wed, 21 May 2025 09:12:52 +0200 Subject: [PATCH] [Clang] Fix a regression introduced by #140576 Lambda bodies should not be treated as subexpressions of the enclosing scope. --- clang/lib/Sema/SemaExpr.cpp | 5 ++--- clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index b18e83b605e4f..5e06c4bf89766 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -17777,13 +17777,12 @@ void Sema::PushExpressionEvaluationContextForFunction( Current.InImmediateEscalatingFunctionContext = getLangOpts().CPlusPlus20 && FD->isImmediateEscalating(); - if (isLambdaMethod(FD)) { - Current.InDiscardedStatement = Parent.isDiscardedStatementContext(); + if (isLambdaMethod(FD)) Current.InImmediateFunctionContext = FD->isConsteval() || (isLambdaMethod(FD) && (Parent.isConstantEvaluated() || Parent.isImmediateFunctionContext())); - } else { + else Current.InImmediateFunctionContext = FD->isConsteval(); } } diff --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp index 20125cc5d4a9c..054defc3470e7 100644 --- a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp +++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp @@ -208,6 +208,14 @@ void test() { } } + +void regression() { + if constexpr (false) { + auto lam = []() { return 0; }; + 1 | lam(); + } +} + } #endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits