[clang] f4cebe5 - [Clang] Fix a regression introduced by #140576 (#140859)
via cfe-commits
cfe-commits at lists.llvm.org
Wed May 21 01:18:18 PDT 2025
Author: cor3ntin
Date: 2025-05-21T10:18:14+02:00
New Revision: f4cebe5d73c24ab53917bd58aedc9db892a164ae
URL: https://github.com/llvm/llvm-project/commit/f4cebe5d73c24ab53917bd58aedc9db892a164ae
DIFF: https://github.com/llvm/llvm-project/commit/f4cebe5d73c24ab53917bd58aedc9db892a164ae.diff
LOG: [Clang] Fix a regression introduced by #140576 (#140859)
Lambda bodies should not be treated as subexpressions of the enclosing
scope.
Added:
Modified:
clang/lib/Sema/SemaExpr.cpp
clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
Removed:
################################################################################
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