From 1a31f8df274c88aa56989d2e28caa96d5a3afc99 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 12 Jun 2019 18:32:22 +0000 Subject: [PATCH] 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 --- lib/Sema/SemaInit.cpp | 3 +++ test/CodeGenCXX/temporaries.cpp | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 25aff40f26..1a1d934798 100644 --- a/lib/Sema/SemaInit.cpp +++ b/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; diff --git a/test/CodeGenCXX/temporaries.cpp b/test/CodeGenCXX/temporaries.cpp index 294ff29a8e..d15e0fa05b 100644 --- a/test/CodeGenCXX/temporaries.cpp +++ b/test/CodeGenCXX/temporaries.cpp @@ -896,3 +896,21 @@ namespace Conditional { // CHECK: br label A &&r = b ? static_cast(B()) : static_cast(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 -- 2.50.1