[clang] [Clang] Do not inherit immediate-function context in lambda bodies (PR #214002)
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 6 01:53:11 PDT 2026
================
@@ -18273,13 +18273,17 @@ void Sema::PushExpressionEvaluationContextForFunction(
Current.InImmediateEscalatingFunctionContext =
getLangOpts().CPlusPlus20 && FD->isImmediateEscalating();
- if (isLambdaMethod(FD))
- Current.InImmediateFunctionContext =
- FD->isConsteval() ||
- (isLambdaMethod(FD) && (Parent.isConstantEvaluated() ||
- Parent.isImmediateFunctionContext()));
- else
- Current.InImmediateFunctionContext = FD->isConsteval();
+ const bool InheritParentImmediateContext =
+ isLambdaMethod(FD) && !isLambdaCallOperator(FD);
+
+ // A lambda call operator body is not a subexpression of the enclosing
+ // lambda-expression. Other lambda methods may be synthesized while
+ // processing the lambda and need to inherit the enclosing evaluation
+ // context.
+ Current.InImmediateFunctionContext =
+ FD->isConsteval() ||
+ (InheritParentImmediateContext &&
+ (Parent.isConstantEvaluated() || Parent.isImmediateFunctionContext()));
----------------
cor3ntin wrote:
I think the whole thing can be simplified to
```
Current.InImmediateFunctionContext = FD->isConsteval();
```
https://github.com/llvm/llvm-project/pull/214002
More information about the cfe-commits
mailing list