]> granicus.if.org Git - clang/commitdiff
PR16502: Fix a dumb bug where we might look past the last initializer in an
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 1 Jul 2013 06:08:20 +0000 (06:08 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 1 Jul 2013 06:08:20 +0000 (06:08 +0000)
InitListExpr.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185304 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/SemaCXX/decl-init-ref.cpp

index f59571a4865908cc4a33315b40a2acc82e8ea082..18328553d38606ce43659fe5e237f9e723832068 100644 (file)
@@ -5346,6 +5346,8 @@ static void performLifetimeExtension(Expr *Init, const ValueDecl *ExtendingD) {
         for (RecordDecl::field_iterator I = RD->field_begin(),
                                         E = RD->field_end();
              I != E; ++I) {
+          if (Index >= ILE->getNumInits())
+            break;
           if (I->isUnnamedBitfield())
             continue;
           Expr *SubInit = ILE->getInit(Index);
index 6802e0c52c5929b3131fe039fb68aadc3a479651..2d0c9cb4ffbec2a5df8c04ee7c73e641c7b0c781 100644 (file)
@@ -30,3 +30,9 @@ PR6139 x = {{A()}}; // expected-error{{non-const lvalue reference to type 'A [1]
 
 struct PR6139b { A (&x)[1]; };
 PR6139b y = {A()}; // expected-error{{non-const lvalue reference to type 'A [1]' cannot bind to a temporary of type 'A'}}
+
+namespace PR16502 {
+  struct A { int &&temporary; int x, y; };
+  int f();
+  const A &c = { 10, ++c.temporary };
+}