summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2015-01-10 01:28:13 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2015-01-10 01:28:13 +0000
commitdbc82492248a72fafa40e3ecfd48b28a271d7b99 (patch)
tree7d0e15b38a288d6ef03bf7355bd67031bf1e9a5b
parent43a0f99b103dc9c2546e650b99f5501e49e74dd2 (diff)
downloadbcm5719-llvm-dbc82492248a72fafa40e3ecfd48b28a271d7b99.tar.gz
bcm5719-llvm-dbc82492248a72fafa40e3ecfd48b28a271d7b99.zip
Fix temporary lifetime extension from an initializer using braced "functional"
cast notation T{...} when T is a reference type. llvm-svn: 225571
-rw-r--r--clang/lib/Sema/SemaInit.cpp14
-rw-r--r--clang/test/CodeGenCXX/temporaries.cpp7
2 files changed, 14 insertions, 7 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index b57e029ddfd..569ef307474 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/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<InitListExpr>(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<InitListExpr>(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<const Expr *, 2> CommaLHSs;
diff --git a/clang/test/CodeGenCXX/temporaries.cpp b/clang/test/CodeGenCXX/temporaries.cpp
index 7f5c7af0386..89677cb1e4e 100644
--- a/clang/test/CodeGenCXX/temporaries.cpp
+++ b/clang/test/CodeGenCXX/temporaries.cpp
@@ -42,6 +42,13 @@ namespace PR20227 {
// CHECK: @_ZGRN7PR202271cE_ = private global
}
+namespace BraceInit {
+ typedef const int &CIR;
+ CIR x = CIR{3};
+ // CHECK: @_ZGRN9BraceInit1xE_ = private constant i32 3
+ // CHECK: @_ZN9BraceInit1xE = constant i32* @_ZGRN9BraceInit1xE_
+}
+
struct A {
A();
~A();
OpenPOWER on IntegriCloud