r363188 - PR42220: take into account the possibility of aggregates with base

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 12 11:32:22 PDT 2019


Author: rsmith
Date: Wed Jun 12 11:32:22 2019
New Revision: 363188

URL: http://llvm.org/viewvc/llvm-project?rev=363188&view=rev
Log:
PR42220: take into account the possibility of aggregates with base
classes when checking an InitListExpr for lifetime extension.

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/CodeGenCXX/temporaries.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=363188&r1=363187&r2=363188&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Jun 12 11:32:22 2019
@@ -6860,6 +6860,9 @@ static void visitLocalsRetainedByInitial
                                               RK_ReferenceBinding, Visit);
       else {
         unsigned Index = 0;
+        for (; Index < RD->getNumBases() && Index < ILE->getNumInits(); ++Index)
+          visitLocalsRetainedByInitializer(Path, ILE->getInit(Index), Visit,
+                                           RevisitSubinits);
         for (const auto *I : RD->fields()) {
           if (Index >= ILE->getNumInits())
             break;

Modified: cfe/trunk/test/CodeGenCXX/temporaries.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/temporaries.cpp?rev=363188&r1=363187&r2=363188&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/temporaries.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/temporaries.cpp Wed Jun 12 11:32:22 2019
@@ -896,3 +896,21 @@ namespace Conditional {
   // CHECK: br label
   A &&r = b ? static_cast<A&&>(B()) : static_cast<A&&>(C());
 }
+
+#if __cplusplus >= 201703L
+namespace PR42220 {
+  struct X { X(); ~X(); };
+  struct A { X &&x; };
+  struct B : A {};
+  void g() noexcept;
+  // CHECK-CXX17-LABEL: define{{.*}} @_ZN7PR422201fEv(
+  void f() {
+    // CHECK-CXX17: call{{.*}} @_ZN7PR422201XC1Ev(
+    B &&b = {X()};
+    // CHECK-CXX17-NOT: call{{.*}} @_ZN7PR422201XD1Ev(
+    // CHECK-CXX17: call{{.*}} @_ZN7PR422201gEv(
+    g();
+    // CHECK-CXX17: call{{.*}} @_ZN7PR422201XD1Ev(
+  }
+}
+#endif




More information about the cfe-commits mailing list