]> granicus.if.org Git - clang/commitdiff
Make sure to count the struct elements correctly; here, we want the
authorEli Friedman <eli.friedman@gmail.com>
Sat, 9 Aug 2008 23:45:45 +0000 (23:45 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 9 Aug 2008 23:45:45 +0000 (23:45 +0000)
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

lib/Sema/SemaInit.cpp
test/Sema/unnamed-bitfield-init.c [new file with mode: 0644]

index 1889bafacb08ab92ca7fbbc24ce33a1d53354578..bc38de3633a6741a105912bdc421a0d0cb0aa839 100644 (file)
@@ -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/test/Sema/unnamed-bitfield-init.c b/test/Sema/unnamed-bitfield-init.c
new file mode 100644 (file)
index 0000000..3a3869a
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: clang -fsyntax-only -verify %s
+typedef struct {
+        int a; int : 24; char b;
+} S;
+
+S a = { 1, 2 };