summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2008-08-09 23:45:45 +0000
committerEli Friedman <eli.friedman@gmail.com>2008-08-09 23:45:45 +0000
commita3b2f6f2af5afad707a91b33b260b769fb57bf7f (patch)
tree0f12cdb19967797cc4231059e6821709e5e05606
parent121ba0c4d34b59512db1309fc2e511e0b36a5fe0 (diff)
downloadbcm5719-llvm-a3b2f6f2af5afad707a91b33b260b769fb57bf7f.tar.gz
bcm5719-llvm-a3b2f6f2af5afad707a91b33b260b769fb57bf7f.zip
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
-rw-r--r--clang/lib/Sema/SemaInit.cpp3
-rw-r--r--clang/test/Sema/unnamed-bitfield-init.c6
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 1889bafacb0..bc38de3633a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -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())
diff --git a/clang/test/Sema/unnamed-bitfield-init.c b/clang/test/Sema/unnamed-bitfield-init.c
new file mode 100644
index 00000000000..3a3869ab6df
--- /dev/null
+++ b/clang/test/Sema/unnamed-bitfield-init.c
@@ -0,0 +1,6 @@
+// RUN: clang -fsyntax-only -verify %s
+typedef struct {
+ int a; int : 24; char b;
+} S;
+
+S a = { 1, 2 };
OpenPOWER on IntegriCloud