浏览代码

PR42220: take into account the possibility of aggregates with base
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

Richard Smith 6 年之前
父节点
当前提交
1a31f8df27
共有 2 个文件被更改,包括 21 次插入0 次删除
  1. 3 0
      lib/Sema/SemaInit.cpp
  2. 18 0
      test/CodeGenCXX/temporaries.cpp

+ 3 - 0
lib/Sema/SemaInit.cpp

@@ -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;

+ 18 - 0
test/CodeGenCXX/temporaries.cpp

@@ -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