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);
true, TopLevelObject))
hadError = true;
- // Abort early for unions: the designator handled the
- // initialization of the appropriate field.
- if (DeclType->isUnionType())
- break;
-
+ InitializedSomething = true;
continue;
}
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;
CheckSubElementType(IList, Field->getType(), Index,
StructuredList, StructuredIndex);
+ InitializedSomething = true;
if (DeclType->isUnionType()) {
// Initialize the first field within the union.
StructuredList->setInitializedFieldInUnion(*Field);
- break;
}
++Field;
.f.arr[3] = 1,
.arr = { &f }
};
+
+typedef unsigned char u_char;
+typedef unsigned short u_short;
+
+union wibble {
+ u_char arr1[6];
+ u_short arr2[3];
+};
+
+const union wibble wobble = { .arr2[0] = 0xffff,
+ .arr2[1] = 0xffff,
+ .arr2[2] = 0xffff };
+
+const union wibble wobble2 = { .arr2 = {4, 5, 6}, 7 }; // expected-error{{excess elements in union initializer}}