Index: lib/Sema/SemaInit.cpp =================================================================== --- lib/Sema/SemaInit.cpp +++ lib/Sema/SemaInit.cpp @@ -1730,6 +1730,12 @@ // worthwhile to skip over the rest of the initializer, though. RecordDecl *RD = DeclType->getAs()->getDecl(); RecordDecl::field_iterator FieldEnd = RD->field_end(); + SmallVector, 10> RemainingFields; + unsigned Fieldidx = 0; + for (auto f = Field; f != FieldEnd; ++f) { + RemainingFields.push_back({f, 0}); + } + RemainingFields.push_back({FieldEnd, 0}); bool InitializedSomething = false; bool CheckForMissingFields = true; while (Index < IList->getNumInits()) { @@ -1750,6 +1756,18 @@ true, TopLevelObject)) hadError = true; + unsigned idx = 0; + auto it = std::find_if(RemainingFields.begin(), RemainingFields.end(), + [&Field, &FieldEnd, &idx](std::pair f) { + ++idx; + return (f.first == FieldEnd || ++f.first == Field); + }); + assert(it != RemainingFields.end()); + if (it->first != FieldEnd) { + Fieldidx = idx; + ++it->second; + } + InitializedSomething = true; // Disable check for missing fields when designators are used. @@ -1773,6 +1791,7 @@ if (Field->isUnnamedBitfield()) { // Don't initialize unnamed bitfields, e.g. "int : 20;" + ++RemainingFields[Fieldidx++].second; ++Field; continue; } @@ -1786,6 +1805,7 @@ IList->getInit(Index)->getLocStart()); if (InvalidUse) { ++Index; + ++RemainingFields[Fieldidx++].second; ++Field; hadError = true; continue; @@ -1802,6 +1822,7 @@ StructuredList->setInitializedFieldInUnion(*Field); } + ++RemainingFields[Fieldidx++].second; ++Field; } @@ -1822,11 +1843,14 @@ } // Check that any remaining fields can be value-initialized. - if (VerifyOnly && Field != FieldEnd && !DeclType->isUnionType() && - !Field->getType()->isIncompleteArrayType()) { - // FIXME: Should check for holes left by designated initializers too. - for (; Field != FieldEnd && !hadError; ++Field) { - if (!Field->isUnnamedBitfield() && !Field->hasInClassInitializer()) + if (VerifyOnly && !DeclType->isUnionType()) { + for (auto Pair : RemainingFields) { + Field = Pair.first; + if (Field == FieldEnd || hadError) + break; + unsigned count = Pair.second; + if (count == 0 && !Field->getType()->isIncompleteArrayType() && + !Field->isUnnamedBitfield() && !Field->hasInClassInitializer()) CheckEmptyInitializable( InitializedEntity::InitializeMember(*Field, &Entity), IList->getLocEnd()); Index: test/SemaCXX/cxx0x-initializer-constructor.cpp =================================================================== --- test/SemaCXX/cxx0x-initializer-constructor.cpp +++ test/SemaCXX/cxx0x-initializer-constructor.cpp @@ -407,3 +407,34 @@ [0] = 1, [2] = 3 }; // expected-error {{ambiguous}} expected-note {{in implicit initialization of array element 1}} } + +namespace PR23514 { +struct Test { + int& a; + int& b; +}; + +int d = 0; +auto a = Test { .b = d, .a = d, }; + +struct S { // expected-note-re 2{{candidate constructor (the implicit {{.*}} constructor) not viable: requires 1 argument, but 0 were provided}} + S(int a) {} // expected-note {{candidate constructor not viable: requires single argument 'a', but no arguments were provided}} +}; + +struct P { + char i1; + char i2; + S s; +}; + +P p1 { .s = 2, .i1 = 1, 1, }; +P p2 { .s = 2, .i1 = 1, }; + +struct PP { + char i1; + S s1; + S s2; // expected-note {{in implicit initialization of field 's2' with omitted initializer}} +}; + +PP pp { .s1 = 2, .i1 = 1, }; // expected-error {{no matching constructor for initialization of 'PR23514::S'}} +}