diff options
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 12 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 13 |
2 files changed, 23 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index a2e05e0094f..beffe414f56 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -8814,13 +8814,21 @@ Sema::DeclGroupPtrTy Sema::FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, if (DS.isTypeSpecOwned()) Decls.push_back(DS.getRepAsDecl()); + DeclaratorDecl *FirstDeclaratorInGroup = 0; for (unsigned i = 0, e = Group.size(); i != e; ++i) - if (Decl *D = Group[i]) + if (Decl *D = Group[i]) { + if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) + if (!FirstDeclaratorInGroup) + FirstDeclaratorInGroup = DD; Decls.push_back(D); + } if (DeclSpec::isDeclRep(DS.getTypeSpecType())) { - if (const TagDecl *Tag = dyn_cast_or_null<TagDecl>(DS.getRepAsDecl())) + if (TagDecl *Tag = dyn_cast_or_null<TagDecl>(DS.getRepAsDecl())) { HandleTagNumbering(*this, Tag); + if (!Tag->hasNameForLinkage() && !Tag->hasDeclaratorForAnonDecl()) + Tag->setDeclaratorForAnonDecl(FirstDeclaratorInGroup); + } } return BuildDeclaratorGroup(Decls, DS.containsPlaceholderType()); diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index cc9cb6317a1..8cd37258b6a 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3356,6 +3356,19 @@ void Sema::BuildVariableInstantiation( NewVar->setReferenced(OldVar->isReferenced()); } + // See if the old variable had a type-specifier that defined an anonymous tag. + // If it did, mark the new variable as being the declarator for the new + // anonymous tag. + if (const TagType *OldTagType = OldVar->getType()->getAs<TagType>()) { + TagDecl *OldTag = OldTagType->getDecl(); + if (OldTag->getDeclaratorForAnonDecl() == OldVar) { + TagDecl *NewTag = NewVar->getType()->castAs<TagType>()->getDecl(); + assert(!NewTag->hasNameForLinkage() && + !NewTag->hasDeclaratorForAnonDecl()); + NewTag->setDeclaratorForAnonDecl(NewVar); + } + } + InstantiateAttrs(TemplateArgs, OldVar, NewVar, LateAttrs, StartingScope); if (NewVar->hasAttrs()) |

