[cfe-commits] r54601 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/Sema/unnamed-bitfield-init.c
Eli Friedman
eli.friedman at gmail.com
Sat Aug 9 16:45:45 PDT 2008
Author: efriedma
Date: Sat Aug 9 18:45:45 2008
New Revision: 54601
URL: http://llvm.org/viewvc/llvm-project?rev=54601&view=rev
Log:
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.
Added:
cfe/trunk/test/Sema/unnamed-bitfield-init.c
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=54601&r1=54600&r2=54601&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Sat Aug 9 18:45:45 2008
@@ -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())
Added: cfe/trunk/test/Sema/unnamed-bitfield-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/unnamed-bitfield-init.c?rev=54601&view=auto
==============================================================================
--- cfe/trunk/test/Sema/unnamed-bitfield-init.c (added)
+++ cfe/trunk/test/Sema/unnamed-bitfield-init.c Sat Aug 9 18:45:45 2008
@@ -0,0 +1,6 @@
+// RUN: clang -fsyntax-only -verify %s
+typedef struct {
+ int a; int : 24; char b;
+} S;
+
+S a = { 1, 2 };
More information about the cfe-commits
mailing list