diff options
author | Anders Carlsson <andersca@mac.com> | 2009-09-01 04:26:58 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-09-01 04:26:58 +0000 |
commit | d8b285fee4471f393da8ee30f552ceacdc362afa (patch) | |
tree | cdd1e51b6106266e1fd0365e71384ea3c11187e5 /lib/Sema/SemaTemplateInstantiateDecl.cpp | |
parent | d6139895f43d161a972d134ffda4229d2f548eb6 (diff) |
Don't assert when instantiating member references to fields in anonymous structs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80657 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiateDecl.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index c5b2894c49..84e464aba3 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -245,6 +245,11 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { if (Invalid) Field->setInvalidDecl(); + if (!Field->getDeclName()) { + // Keep track of where this decl came from. + SemaRef.Context.setInstantiatedFromUnnamedFieldDecl(Field, D); + } + Owner->addDecl(Field); } @@ -441,6 +446,8 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { if (Decl::FriendObjectKind FOK = D->getFriendObjectKind()) Record->setObjectOfFriendDecl(FOK == Decl::FOK_Declared); + Record->setAnonymousStructOrUnion(D->isAnonymousStructOrUnion()); + Owner->addDecl(Record); return Record; } @@ -1274,8 +1281,14 @@ static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) { if (ClassTemplateDecl *Temp = dyn_cast<ClassTemplateDecl>(Other)) return isInstantiationOf(cast<ClassTemplateDecl>(D), Temp); - // FIXME: How can we find instantiations of anonymous unions? - + if (FieldDecl *Field = dyn_cast<FieldDecl>(Other)) { + if (!Field->getDeclName()) { + // This is an unnamed field. + return Ctx.getInstantiatedFromUnnamedFieldDecl(Field) == + cast<FieldDecl>(D); + } + } + return D->getDeclName() && isa<NamedDecl>(Other) && D->getDeclName() == cast<NamedDecl>(Other)->getDeclName(); } |