[cfe-commits] r74554 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/SemaCXX/constructor-initializer.cpp
Fariborz Jahanian
fjahanian at apple.com
Tue Jun 30 14:53:00 PDT 2009
Author: fjahanian
Date: Tue Jun 30 16:52:59 2009
New Revision: 74554
URL: http://llvm.org/viewvc/llvm-project?rev=74554&view=rev
Log:
Diagnose multiple initialization of anonymous union
fields in the ctor-initializer list.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/constructor-initializer.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=74554&r1=74553&r2=74554&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Jun 30 16:52:59 2009
@@ -782,7 +782,14 @@
for (unsigned i = 0; i < NumMemInits; i++) {
CXXBaseOrMemberInitializer *Member =
static_cast<CXXBaseOrMemberInitializer*>(MemInits[i]);
- CXXBaseOrMemberInitializer *&PrevMember = Members[Member->getBaseOrMember()];
+ void *KeyToMember = Member->getBaseOrMember();
+ // For fields injected into the class via declaration of an anonymous union,
+ // use its anonymous union class declaration as the unique key.
+ if (FieldDecl *Field = Member->getMember())
+ if (Field->getDeclContext()->isRecord() &&
+ cast<RecordDecl>(Field->getDeclContext())->isAnonymousStructOrUnion())
+ KeyToMember = static_cast<void *>(Field->getDeclContext());
+ CXXBaseOrMemberInitializer *&PrevMember = Members[KeyToMember];
if (!PrevMember) {
PrevMember = Member;
continue;
Modified: cfe/trunk/test/SemaCXX/constructor-initializer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constructor-initializer.cpp?rev=74554&r1=74553&r2=74554&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constructor-initializer.cpp (original)
+++ cfe/trunk/test/SemaCXX/constructor-initializer.cpp Tue Jun 30 16:52:59 2009
@@ -66,3 +66,11 @@
Z() : S(), X(), E() {} // expected-error {{type 'class E' is not a direct or virtual base of 'Z'}}
};
+class U {
+ union { int a; char* p; };
+ union { int b; double d; };
+
+ U() : a(1), p(0), d(1.0) {} // expected-error {{multiple initializations given for non-static member 'p'}} \
+ // expected-note {{previous initialization is here}}
+};
+
More information about the cfe-commits
mailing list