[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 11 05:47:56 PST 2024


================
@@ -6289,9 +6289,19 @@ ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc,
     ImmediateCallVisitor V(getASTContext());
     if (!NestedDefaultChecking)
       V.TraverseDecl(Param);
-    if (V.HasImmediateCalls) {
-      ExprEvalContexts.back().DelayedDefaultInitializationContext = {
-          CallLoc, Param, CurContext};
+
+    // Rewrite the call argument that was created from the corresponding
+    // parameter's default argument.
+    if (V.HasImmediateCalls || IsInLifetimeExtendingContext) {
+      if (V.HasImmediateCalls)
+        ExprEvalContexts.back().DelayedDefaultInitializationContext = {
+            CallLoc, Param, CurContext};
+      // Pass down lifetime extendning flag, and collect temporaries in
----------------
AaronBallman wrote:

```suggestion
      // Pass down lifetime extending flag, and collect temporaries in
```

https://github.com/llvm/llvm-project/pull/76361


More information about the cfe-commits mailing list