]> granicus.if.org Git - clang/commitdiff
PR42220: take into account the possibility of aggregates with base
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 12 Jun 2019 18:32:22 +0000 (18:32 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 12 Jun 2019 18:32:22 +0000 (18:32 +0000)
classes when checking an InitListExpr for lifetime extension.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363188 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/CodeGenCXX/temporaries.cpp

index 25aff40f26f76b51e195fbc77363257394841e75..1a1d93479853ccd3bbfebb0528e8b38f1b0eec92 100644 (file)
@@ -6860,6 +6860,9 @@ static void visitLocalsRetainedByInitializer(IndirectLocalPath &Path,
                                               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;
index 294ff29a8eabf4315f71d22060245855c1bcb59f..d15e0fa05bd867a260719c88595e35137cc9394b 100644 (file)
@@ -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