Skip to content

Commit f4cebe5

Browse files
authored
[Clang] Fix a regression introduced by #140576 (#140859)
Lambda bodies should not be treated as subexpressions of the enclosing scope.
1 parent 9f4cea2 commit f4cebe5

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17777,15 +17777,13 @@ void Sema::PushExpressionEvaluationContextForFunction(
1777717777
Current.InImmediateEscalatingFunctionContext =
1777817778
getLangOpts().CPlusPlus20 && FD->isImmediateEscalating();
1777917779

17780-
if (isLambdaMethod(FD)) {
17781-
Current.InDiscardedStatement = Parent.isDiscardedStatementContext();
17780+
if (isLambdaMethod(FD))
1778217781
Current.InImmediateFunctionContext =
1778317782
FD->isConsteval() ||
1778417783
(isLambdaMethod(FD) && (Parent.isConstantEvaluated() ||
1778517784
Parent.isImmediateFunctionContext()));
17786-
} else {
17785+
else
1778717786
Current.InImmediateFunctionContext = FD->isConsteval();
17788-
}
1778917787
}
1779017788
}
1779117789

clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ void test() {
208208

209209
}
210210
}
211+
212+
void regression() {
213+
if constexpr (false) {
214+
auto lam = []() { return 0; };
215+
1 | lam(); // expected-warning {{unused}}
216+
}
217+
}
218+
211219
}
212220

213221
#endif

0 commit comments

Comments
 (0)