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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54601 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index 1889baf..bc38de3 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -286,7 +286,8 @@
// 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())