@@ -17749,6 +17749,47 @@ Sema::PushExpressionEvaluationContext(
1774917749 PushExpressionEvaluationContext(NewContext, ClosureContextDecl, ExprContext);
1775017750}
1775117751
17752+ void Sema::PushExpressionEvaluationContextForFunction(
17753+ ExpressionEvaluationContext NewContext, FunctionDecl *FD) {
17754+ // [expr.const]/p14.1
17755+ // An expression or conversion is in an immediate function context if it is
17756+ // potentially evaluated and either: its innermost enclosing non-block scope
17757+ // is a function parameter scope of an immediate function.
17758+ PushExpressionEvaluationContext(
17759+ FD && FD->isConsteval()
17760+ ? ExpressionEvaluationContext::ImmediateFunctionContext
17761+ : NewContext);
17762+ const Sema::ExpressionEvaluationContextRecord &Parent =
17763+ parentEvaluationContext();
17764+ Sema::ExpressionEvaluationContextRecord &Current = currentEvaluationContext();
17765+
17766+ Current.InDiscardedStatement = false;
17767+
17768+ if (FD) {
17769+
17770+ // Each ExpressionEvaluationContextRecord also keeps track of whether the
17771+ // context is nested in an immediate function context, so smaller contexts
17772+ // that appear inside immediate functions (like variable initializers) are
17773+ // considered to be inside an immediate function context even though by
17774+ // themselves they are not immediate function contexts. But when a new
17775+ // function is entered, we need to reset this tracking, since the entered
17776+ // function might be not an immediate function.
17777+
17778+ Current.InImmediateEscalatingFunctionContext =
17779+ getLangOpts().CPlusPlus20 && FD->isImmediateEscalating();
17780+
17781+ if (isLambdaMethod(FD)) {
17782+ Current.InDiscardedStatement = Parent.isDiscardedStatementContext();
17783+ Current.InImmediateFunctionContext =
17784+ FD->isConsteval() ||
17785+ (isLambdaMethod(FD) && (Parent.isConstantEvaluated() ||
17786+ Parent.isImmediateFunctionContext()));
17787+ } else {
17788+ Current.InImmediateFunctionContext = FD->isConsteval();
17789+ }
17790+ }
17791+ }
17792+
1775217793namespace {
1775317794
1775417795const DeclRefExpr *CheckPossibleDeref(Sema &S, const Expr *PossibleDeref) {
0 commit comments