diff options
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 3 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/temporaries.cpp | 18 |
2 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 25aff40f26f..1a1d9347985 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/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/clang/test/CodeGenCXX/temporaries.cpp b/clang/test/CodeGenCXX/temporaries.cpp index 294ff29a8ea..d15e0fa05bd 100644 --- a/clang/test/CodeGenCXX/temporaries.cpp +++ b/clang/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 |