[clang] Reapply "[Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer" (PR #97308)

via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 7 22:58:53 PDT 2024


================
@@ -750,8 +750,22 @@ void InitListChecker::FillInEmptyInitForField(unsigned Init, FieldDecl *Field,
     if (Field->hasInClassInitializer()) {
       if (VerifyOnly)
         return;
-
-      ExprResult DIE = SemaRef.BuildCXXDefaultInitExpr(Loc, Field);
+      ExprResult DIE;
+      {
+        // Enter a default initializer rebuild context, then we can support
+        // lifetime extension of temporary created by aggregate initialization
+        // using a default member initializer.
+        // CWG1815 (https://wg21.link/CWG1815).
+        EnterExpressionEvaluationContext RebuildDefaultInit(
+            SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated,
+            /*LambdaContextDecl=*/nullptr,
+            Sema::ExpressionEvaluationContextRecord::EK_Other, true);
----------------
yronglin wrote:

Fixed.

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


More information about the cfe-commits mailing list