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

Hubert Tong via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 18 01:37:30 PDT 2024


================
@@ -6375,12 +6383,16 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) {
   ImmediateCallVisitor V(getASTContext());
   if (!NestedDefaultChecking)
     V.TraverseDecl(Field);
-  if (V.HasImmediateCalls) {
+  if (V.HasImmediateCalls || InLifetimeExtendingContext) {
     ExprEvalContexts.back().DelayedDefaultInitializationContext = {Loc, Field,
                                                                    CurContext};
     ExprEvalContexts.back().IsCurrentlyCheckingDefaultArgumentOrInitializer =
         NestedDefaultChecking;
 
+    // Pass down lifetime extending flag, and collect temporaries in
+    // CreateMaterializeTemporaryExpr when we rewrite the call argument.
+    keepInLifetimeExtendingContext();
+    keepInMaterializeTemporaryObjectContext();
----------------
hubert-reinterpretcast wrote:

> @hubert-reinterpretcast Could you please give me an example where `CXXDefaultInitExpr` has to be lifetime-extended?

https://github.com/llvm/llvm-project/issues/85613

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


More information about the cfe-commits mailing list