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