diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 15 | 
1 files changed, 7 insertions, 8 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 27d8d5aa2e5..b54a8d674b2 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -742,14 +742,13 @@ void InitListChecker::CheckStructUnionTypes(InitListExpr *IList,      return;    } - -    // If structDecl is a forward declaration, this loop won't do    // anything except look at designated initializers; That's okay,    // because an error should get printed out elsewhere. It might be    // worthwhile to skip over the rest of the initializer, though.    RecordDecl *RD = DeclType->getAsRecordType()->getDecl();    RecordDecl::field_iterator FieldEnd = RD->field_end(); +  bool InitializedSomething = false;    while (Index < IList->getNumInits()) {      Expr *Init = IList->getInit(Index); @@ -768,11 +767,7 @@ void InitListChecker::CheckStructUnionTypes(InitListExpr *IList,                                       true, TopLevelObject))          hadError = true; -      // Abort early for unions: the designator handled the -      // initialization of the appropriate field. -      if (DeclType->isUnionType()) -        break; - +      InitializedSomething = true;        continue;      } @@ -781,6 +776,10 @@ void InitListChecker::CheckStructUnionTypes(InitListExpr *IList,        break;      } +    // We've already initialized a member of a union. We're done. +    if (InitializedSomething && DeclType->isUnionType()) +      break; +      // If we've hit the flexible array member at the end, we're done.      if (Field->getType()->isIncompleteArrayType())        break; @@ -793,11 +792,11 @@ void InitListChecker::CheckStructUnionTypes(InitListExpr *IList,      CheckSubElementType(IList, Field->getType(), Index,                          StructuredList, StructuredIndex); +    InitializedSomething = true;      if (DeclType->isUnionType()) {        // Initialize the first field within the union.        StructuredList->setInitializedFieldInUnion(*Field); -      break;      }      ++Field;  | 

