forked from OSchip/llvm-project
Make sure to count the struct elements correctly; here, we want the
member count. The count returned by numStructUnionElements is the number of initializers that will be consumed, not the number of members to iterate through. Fixes PR2534. llvm-svn: 54601
This commit is contained in:
parent
121ba0c4d3
commit
a3b2f6f2af
|
@ -286,7 +286,8 @@ void InitListChecker::CheckStructUnionTypes(InitListExpr *IList,
|
|||
// If structDecl is a forward declaration, this loop won't do anything;
|
||||
// That's okay, because an error should get printed out elsewhere. It
|
||||
// might be worthwhile to skip over the rest of the initializer, though.
|
||||
int numMembers = numStructUnionElements(DeclType);
|
||||
int numMembers = DeclType->getAsRecordType()->getDecl()->getNumMembers() -
|
||||
structDecl->hasFlexibleArrayMember();
|
||||
for (int i = 0; i < numMembers; i++) {
|
||||
// Don't attempt to go past the end of the init list
|
||||
if (Index >= IList->getNumInits())
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
// RUN: clang -fsyntax-only -verify %s
|
||||
typedef struct {
|
||||
int a; int : 24; char b;
|
||||
} S;
|
||||
|
||||
S a = { 1, 2 };
|
Loading…
Reference in New Issue