[clang] [Clang] Fix a regression introduced by #140576 (PR #140859)
via cfe-commits
cfe-commits at lists.llvm.org
Wed May 21 00:29:12 PDT 2025
https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/140859
>From 1e7330b89327ea02271d54349ab3b01b8a495805 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at 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 | 6 ++----
clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp | 8 ++++++++
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index b18e83b605e4f..66dac21bf5818 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17777,15 +17777,13 @@ 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..ac21e36daf870 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(); // expected-warning {{unused}}
+ }
+}
+
}
#endif
More information about the cfe-commits
mailing list