From 22c634704f7f4a0803f08bebd1e1bc662f5ab77f Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 10 Jan 2015 01:28:13 +0000 Subject: [PATCH] Fix temporary lifetime extension from an initializer using braced "functional" cast notation T{...} when T is a reference type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225571 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaInit.cpp | 14 +++++++------- test/CodeGenCXX/temporaries.cpp | 7 +++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index b57e029ddf..569ef30747 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -5497,18 +5497,18 @@ static void performLifetimeExtension(Expr *Init, static bool performReferenceExtension(Expr *Init, const InitializedEntity *ExtendingEntity) { - if (InitListExpr *ILE = dyn_cast(Init)) { - if (ILE->getNumInits() == 1 && ILE->isGLValue()) { - // This is just redundant braces around an initializer. Step over it. - Init = ILE->getInit(0); - } - } - // Walk past any constructs which we can lifetime-extend across. Expr *Old; do { Old = Init; + if (InitListExpr *ILE = dyn_cast(Init)) { + if (ILE->getNumInits() == 1 && ILE->isGLValue()) { + // This is just redundant braces around an initializer. Step over it. + Init = ILE->getInit(0); + } + } + // Step over any subobject adjustments; we may have a materialized // temporary inside them. SmallVector CommaLHSs; diff --git a/test/CodeGenCXX/temporaries.cpp b/test/CodeGenCXX/temporaries.cpp index 7f5c7af038..89677cb1e4 100644 --- a/test/CodeGenCXX/temporaries.cpp +++ b/test/CodeGenCXX/temporaries.cpp @@ -42,6 +42,13 @@ namespace PR20227 { // CHECK: @_ZGRN7PR202271cE_ = private global } +namespace BraceInit { + typedef const int ○ + CIR x = CIR{3}; + // CHECK: @_ZGRN9BraceInit1xE_ = private constant i32 3 + // CHECK: @_ZN9BraceInit1xE = constant i32* @_ZGRN9BraceInit1xE_ +} + struct A { A(); ~A(); -- 2.40.0