From: Richard Smith Date: Mon, 1 Jul 2013 06:08:20 +0000 (+0000) Subject: PR16502: Fix a dumb bug where we might look past the last initializer in an X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c3af140263c3761665aa2c0aac4266115f5caf1;p=clang PR16502: Fix a dumb bug where we might look past the last initializer in an InitListExpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185304 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index f59571a486..18328553d3 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -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); diff --git a/test/SemaCXX/decl-init-ref.cpp b/test/SemaCXX/decl-init-ref.cpp index 6802e0c52c..2d0c9cb4ff 100644 --- a/test/SemaCXX/decl-init-ref.cpp +++ b/test/SemaCXX/decl-init-ref.cpp @@ -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 }; +}