[cfe-commits] r99891 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/SemaCXX/class-base-member-init.cpp
Anders Carlsson
andersca at mac.com
Tue Mar 30 09:19:37 PDT 2010
Author: andersca
Date: Tue Mar 30 11:19:37 2010
New Revision: 99891
URL: http://llvm.org/viewvc/llvm-project?rev=99891&view=rev
Log:
Fix a bug where we would incorrectly report an error about initializing two fields in an anonymous struct.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/class-base-member-init.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=99891&r1=99890&r2=99891&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Mar 30 11:19:37 2010
@@ -1691,11 +1691,12 @@
// in AnonUnionMember field.
if (MemberMaybeAnon && Field->isAnonymousStructOrUnion())
Field = Member->getAnonUnionMember();
- if (Field->getDeclContext()->isRecord()) {
- RecordDecl *RD = cast<RecordDecl>(Field->getDeclContext());
- if (RD->isAnonymousStructOrUnion())
- return static_cast<void *>(RD);
- }
+
+ // If the field is a member of an anonymous union, we use record decl of the
+ // union as the key.
+ RecordDecl *RD = Field->getParent();
+ if (RD->isAnonymousStructOrUnion() && RD->isUnion())
+ return static_cast<void *>(RD);
return static_cast<void *>(Field);
}
@@ -1719,7 +1720,7 @@
}
if (!Constructor->isDependentContext()) {
- llvm::DenseMap<void*, CXXBaseOrMemberInitializer *>Members;
+ llvm::DenseMap<void*, CXXBaseOrMemberInitializer *> Members;
bool err = false;
for (unsigned i = 0; i < NumMemInits; i++) {
CXXBaseOrMemberInitializer *Member =
@@ -1754,7 +1755,7 @@
SetBaseOrMemberInitializers(Constructor,
reinterpret_cast<CXXBaseOrMemberInitializer **>(MemInits),
- NumMemInits, false, AnyErrors);
+ NumMemInits, /*IsImplicitConstructor=*/false, AnyErrors);
if (Constructor->isDependentContext())
return;
@@ -1929,11 +1930,11 @@
if (!CDtorDecl)
return;
- AdjustDeclIfTemplate(CDtorDecl);
-
if (CXXConstructorDecl *Constructor
= dyn_cast<CXXConstructorDecl>(CDtorDecl.getAs<Decl>()))
- SetBaseOrMemberInitializers(Constructor, 0, 0, false, false);
+ SetBaseOrMemberInitializers(Constructor, 0, 0,
+ /*IsImplicitConstructor=*/false,
+ /*AnyErrors=*/false);
}
bool Sema::RequireNonAbstractType(SourceLocation Loc, QualType T,
@@ -3781,7 +3782,9 @@
DeclContext *PreviousContext = CurContext;
CurContext = Constructor;
- if (SetBaseOrMemberInitializers(Constructor, 0, 0, true, false)) {
+ if (SetBaseOrMemberInitializers(Constructor, 0, 0,
+ /*IsImplicitConstructor=*/true,
+ /*AnyErrors=*/false)) {
Diag(CurrentLocation, diag::note_member_synthesized_at)
<< CXXDefaultConstructor << Context.getTagDeclType(ClassDecl);
Constructor->setInvalidDecl();
Modified: cfe/trunk/test/SemaCXX/class-base-member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/class-base-member-init.cpp?rev=99891&r1=99890&r2=99891&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/class-base-member-init.cpp (original)
+++ cfe/trunk/test/SemaCXX/class-base-member-init.cpp Tue Mar 30 11:19:37 2010
@@ -6,14 +6,23 @@
};
struct D : S {
- D() : b1(0), b2(1), b1(0), S(), S() {} // expected-error {{multiple initializations given for non-static member 'b1'}} \
- // expected-note {{previous initialization is here}} \
- // expected-error {{multiple initializations given for base 'S'}} \
- // expected-note {{previous initialization is here}}
-
+ D() :
+ b1(0), // expected-note {{previous initialization is here}}
+ b2(1),
+ b1(0), // expected-error {{multiple initializations given for non-static member 'b1'}}
+ S(), // expected-note {{previous initialization is here}}
+ S() // expected-error {{multiple initializations given for base 'S'}}
+ {}
int b1;
int b2;
-
};
+struct A {
+ struct {
+ int a;
+ int b;
+ };
+ A();
+};
+A::A() : a(10), b(20) { }
More information about the cfe-commits
mailing list