@@ -5429,8 +5429,6 @@ struct EnsureImmediateInvocationInDefaultArgs
54295429 EnsureImmediateInvocationInDefaultArgs(Sema &SemaRef)
54305430 : TreeTransform(SemaRef) {}
54315431
5432- bool AlwaysRebuild() { return true; }
5433-
54345432 // Lambda can only have immediate invocations in the default
54355433 // args of their parameters, which is transformed upon calling the closure.
54365434 // The body is not a subexpression, so we have nothing to do.
@@ -5472,7 +5470,7 @@ ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc,
54725470 assert(Param->hasDefaultArg() && "can't build nonexistent default arg");
54735471
54745472 bool NestedDefaultChecking = isCheckingDefaultArgumentOrInitializer();
5475- bool NeedRebuild = needRebuildDefaultArgOrInit ();
5473+ bool InLifetimeExtendingContext = isInLifetimeExtendingContext ();
54765474 std::optional<ExpressionEvaluationContextRecord::InitializationContext>
54775475 InitializationContext =
54785476 OutermostDeclarationWithDelayedImmediateInvocations();
@@ -5508,15 +5506,13 @@ ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc,
55085506
55095507 // Rewrite the call argument that was created from the corresponding
55105508 // parameter's default argument.
5511- if (V.HasImmediateCalls ||
5512- (NeedRebuild && isa_and_present<ExprWithCleanups>(Param->getInit()))) {
5509+ if (V.HasImmediateCalls || InLifetimeExtendingContext) {
55135510 if (V.HasImmediateCalls)
55145511 ExprEvalContexts.back().DelayedDefaultInitializationContext = {
55155512 CallLoc, Param, CurContext};
55165513 // Pass down lifetime extending flag, and collect temporaries in
55175514 // CreateMaterializeTemporaryExpr when we rewrite the call argument.
5518- currentEvaluationContext().InLifetimeExtendingContext =
5519- parentEvaluationContext().InLifetimeExtendingContext;
5515+ keepInLifetimeExtendingContext();
55205516 EnsureImmediateInvocationInDefaultArgs Immediate(*this);
55215517 ExprResult Res;
55225518 runWithSufficientStackSpace(CallLoc, [&] {
@@ -5562,7 +5558,7 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) {
55625558 Expr *Init = nullptr;
55635559
55645560 bool NestedDefaultChecking = isCheckingDefaultArgumentOrInitializer();
5565- bool NeedRebuild = needRebuildDefaultArgOrInit();
5561+
55665562 EnterExpressionEvaluationContext EvalContext(
55675563 *this, ExpressionEvaluationContext::PotentiallyEvaluated, Field);
55685564
@@ -5597,27 +5593,12 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) {
55975593 ImmediateCallVisitor V(getASTContext());
55985594 if (!NestedDefaultChecking)
55995595 V.TraverseDecl(Field);
5600-
5601- // CWG1815
5602- // Support lifetime extension of temporary created by aggregate
5603- // initialization using a default member initializer. We should rebuild
5604- // the initializer in a lifetime extension context if the initializer
5605- // expression is an ExprWithCleanups. Then make sure the normal lifetime
5606- // extension code recurses into the default initializer and does lifetime
5607- // extension when warranted.
5608- bool ContainsAnyTemporaries =
5609- isa_and_present<ExprWithCleanups>(Field->getInClassInitializer());
5610- if (Field->getInClassInitializer() &&
5611- !Field->getInClassInitializer()->containsErrors() &&
5612- (V.HasImmediateCalls || (NeedRebuild && ContainsAnyTemporaries))) {
5596+ if (V.HasImmediateCalls) {
56135597 ExprEvalContexts.back().DelayedDefaultInitializationContext = {Loc, Field,
56145598 CurContext};
56155599 ExprEvalContexts.back().IsCurrentlyCheckingDefaultArgumentOrInitializer =
56165600 NestedDefaultChecking;
5617- // Pass down lifetime extending flag, and collect temporaries in
5618- // CreateMaterializeTemporaryExpr when we rewrite the call argument.
5619- currentEvaluationContext().InLifetimeExtendingContext =
5620- parentEvaluationContext().InLifetimeExtendingContext;
5601+
56215602 EnsureImmediateInvocationInDefaultArgs Immediate(*this);
56225603 ExprResult Res;
56235604 runWithSufficientStackSpace(Loc, [&] {
@@ -17694,10 +17675,11 @@ void Sema::PopExpressionEvaluationContext() {
1769417675
1769517676 // Append the collected materialized temporaries into previous context before
1769617677 // exit if the previous also is a lifetime extending context.
17678+ auto &PrevRecord = parentEvaluationContext();
1769717679 if (getLangOpts().CPlusPlus23 && Rec.InLifetimeExtendingContext &&
17698- parentEvaluationContext() .InLifetimeExtendingContext &&
17680+ PrevRecord .InLifetimeExtendingContext &&
1769917681 !Rec.ForRangeLifetimeExtendTemps.empty()) {
17700- parentEvaluationContext() .ForRangeLifetimeExtendTemps.append(
17682+ PrevRecord .ForRangeLifetimeExtendTemps.append(
1770117683 Rec.ForRangeLifetimeExtendTemps);
1770217684 }
1770317685
0 commit comments