[cfe-commits] r80662 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-anonymous-union.cpp
Anders Carlsson
andersca at mac.com
Mon Aug 31 23:22:14 PDT 2009
Author: andersca
Date: Tue Sep 1 01:22:14 2009
New Revision: 80662
URL: http://llvm.org/viewvc/llvm-project?rev=80662&view=rev
Log:
Don't assume that a base is always a RecordType, it can also be a TemplateSpecializationType. Also, make sure to get the instantiated union member.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=80662&r1=80661&r2=80662&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Sep 1 01:22:14 2009
@@ -912,11 +912,21 @@
return static_cast<void *>(Field);
}
+static void *GetKeyForBase(QualType BaseType) {
+ if (const RecordType *RT = BaseType->getAs<RecordType>())
+ return (void *)RT;
+
+ assert(0 && "Unexpected base type!");
+ return 0;
+}
+
static void *GetKeyForMember(CXXBaseOrMemberInitializer *Member,
- bool MemberMaybeAnon=false) {
+ bool MemberMaybeAnon = false) {
// 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 (Member->isMemberInitializer()) {
+ FieldDecl *Field = Member->getMember();
+
// After BuildBaseOrMemberInitializers call, Field is the anonymous union
// data member of the class. Data member used in the initializer list is
// in AnonUnionMember field.
@@ -929,7 +939,8 @@
}
return static_cast<void *>(Field);
}
- return static_cast<RecordType *>(Member->getBaseClass());
+
+ return GetKeyForBase(QualType(Member->getBaseClass(), 0));
}
void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl,
@@ -1003,7 +1014,7 @@
for (CXXRecordDecl::base_class_iterator VBase =
ClassDecl->vbases_begin(),
E = ClassDecl->vbases_end(); VBase != E; ++VBase)
- AllBaseOrMembers.push_back(VBase->getType()->getAs<RecordType>());
+ AllBaseOrMembers.push_back(GetKeyForBase(VBase->getType()));
for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(),
E = ClassDecl->bases_end(); Base != E; ++Base) {
@@ -1011,7 +1022,7 @@
// first.
if (Base->isVirtual())
continue;
- AllBaseOrMembers.push_back(Base->getType()->getAs<RecordType>());
+ AllBaseOrMembers.push_back(GetKeyForBase(Base->getType()));
}
for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(),
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=80662&r1=80661&r2=80662&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue Sep 1 01:22:14 2009
@@ -1145,7 +1145,6 @@
QualType BaseType(Init->getBaseClass(), 0);
BaseType = SubstType(BaseType, TemplateArgs, Init->getSourceLocation(),
New->getDeclName());
- BaseType = Context.getCanonicalType(BaseType);
NewInit = BuildBaseInitializer(BaseType,
(Expr **)NewArgs.data(),
@@ -1158,7 +1157,7 @@
// Is this an anonymous union?
if (FieldDecl *UnionInit = Init->getAnonUnionMember())
- Member = cast<FieldDecl>(UnionInit);
+ Member = cast<FieldDecl>(FindInstantiatedDecl(UnionInit));
else
Member = cast<FieldDecl>(FindInstantiatedDecl(Init->getMember()));
Modified: cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp?rev=80662&r1=80661&r2=80662&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp Tue Sep 1 01:22:14 2009
@@ -1,6 +1,4 @@
-// RUN: clang-cc -fsyntax-only %s
-
-// FIXME: We need to test anonymous structs/unions in templates for real.
+// RUN: clang-cc -fsyntax-only %s -Wall
template <typename T> class A { struct { }; };
@@ -30,4 +28,4 @@
C(void* b) : b(b) { }
};
-C<int> c0;
+C<int> c0(0);
More information about the cfe-commits
mailing list