[cfe-commits] r51557 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/Sema/array-init.c
Eli Friedman
eli.friedman at gmail.com
Sun May 25 07:03:32 PDT 2008
Author: efriedma
Date: Sun May 25 09:03:31 2008
New Revision: 51557
URL: http://llvm.org/viewvc/llvm-project?rev=51557&view=rev
Log:
Count the number of initializable members correctly in structs/unions
with unnamed members.
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Sema/array-init.c
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=51557&r1=51556&r2=51557&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Sun May 25 09:03:31 2008
@@ -38,9 +38,13 @@
int InitListChecker::numStructUnionElements(QualType DeclType) {
RecordDecl *structDecl = DeclType->getAsRecordType()->getDecl();
+ int InitializableMembers = 0;
+ for (int i = 0; i < structDecl->getNumMembers(); i++)
+ if (structDecl->getMember(i)->getIdentifier())
+ ++InitializableMembers;
if (structDecl->getKind() == Decl::Union)
- return std::min(structDecl->getNumMembers(), 1);
- return structDecl->getNumMembers() - structDecl->hasFlexibleArrayMember();
+ return std::min(InitializableMembers, 1);
+ return InitializableMembers - structDecl->hasFlexibleArrayMember();
}
void InitListChecker::CheckImplicitInitList(InitListExpr *ParentIList,
Modified: cfe/trunk/test/Sema/array-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-init.c?rev=51557&r1=51556&r2=51557&view=diff
==============================================================================
--- cfe/trunk/test/Sema/array-init.c (original)
+++ cfe/trunk/test/Sema/array-init.c Sun May 25 09:03:31 2008
@@ -216,3 +216,9 @@
// PR2151
int emptyInit() {struct {} x[] = {6};} //expected-warning{{empty struct extension}} expected-error{{initializer for aggregate with no elements}}
+int noNamedInit() {
+struct {int:5;} x[] = {6}; //expected-error{{initializer for aggregate with no elements}}
+}
+struct {int a; int:5;} noNamedImplicit[] = {1,2,3};
+int noNamedImplicitCheck[sizeof(noNamedImplicit) == 3 * sizeof(*noNamedImplicit) ? 1 : -1];
+
More information about the cfe-commits
mailing list