]> granicus.if.org Git - clang/commitdiff
Fix temporary lifetime extension from an initializer using braced "functional"
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 10 Jan 2015 01:28:13 +0000 (01:28 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 10 Jan 2015 01:28:13 +0000 (01:28 +0000)
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
test/CodeGenCXX/temporaries.cpp

index b57e029ddfdbe7f09fb058ff69629029ad591e5b..569ef307474f79afc3c0277a6bb5e9329a6afb38 100644 (file)
@@ -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;
index 7f5c7af03865475f83f2563f115515cd1c3f2202..89677cb1e4e9c624604247125708ad89d23c1ee6 100644 (file)
@@ -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();