diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index 341c802f50..0f25547675 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -512,6 +512,11 @@ protected: } }; + template typename SpecEntryTraits::DeclType* + findSpecializationImpl(llvm::FoldingSet &Specs, + const TemplateArgument *Args, unsigned NumArgs, + void *&InsertPos); + struct CommonBase { CommonBase() : InstantiatedFromMember(0, false) { } diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index 25df086e73..e69338a773 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -126,6 +126,19 @@ RedeclarableTemplateDecl *RedeclarableTemplateDecl::getNextRedeclaration() { return Common ? Common->Latest : this; } +template +typename RedeclarableTemplateDecl::SpecEntryTraits::DeclType* +RedeclarableTemplateDecl::findSpecializationImpl( + llvm::FoldingSet &Specs, + const TemplateArgument *Args, unsigned NumArgs, + void *&InsertPos) { + typedef SpecEntryTraits SETraits; + llvm::FoldingSetNodeID ID; + EntryType::Profile(ID,Args,NumArgs, getASTContext()); + EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos); + return Entry ? SETraits::getMostRecentDeclaration(Entry) : 0; +} + //===----------------------------------------------------------------------===// // FunctionTemplateDecl Implementation //===----------------------------------------------------------------------===// @@ -152,11 +165,7 @@ RedeclarableTemplateDecl::CommonBase *FunctionTemplateDecl::newCommon() { FunctionDecl * FunctionTemplateDecl::findSpecialization(const TemplateArgument *Args, unsigned NumArgs, void *&InsertPos) { - llvm::FoldingSetNodeID ID; - FunctionTemplateSpecializationInfo::Profile(ID,Args,NumArgs, getASTContext()); - FunctionTemplateSpecializationInfo *Info - = getSpecializations().FindNodeOrInsertPos(ID, InsertPos); - return Info ? Info->Function->getMostRecentDeclaration() : 0; + return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); } //===----------------------------------------------------------------------===// @@ -188,23 +197,15 @@ RedeclarableTemplateDecl::CommonBase *ClassTemplateDecl::newCommon() { ClassTemplateSpecializationDecl * ClassTemplateDecl::findSpecialization(const TemplateArgument *Args, unsigned NumArgs, void *&InsertPos) { - llvm::FoldingSetNodeID ID; - ClassTemplateSpecializationDecl::Profile(ID, Args, NumArgs, getASTContext()); - ClassTemplateSpecializationDecl *D - = getSpecializations().FindNodeOrInsertPos(ID, InsertPos); - return D ? D->getMostRecentDeclaration() : 0; + return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); } ClassTemplatePartialSpecializationDecl * ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args, unsigned NumArgs, void *&InsertPos) { - llvm::FoldingSetNodeID ID; - ClassTemplatePartialSpecializationDecl::Profile(ID, Args, NumArgs, - getASTContext()); - ClassTemplatePartialSpecializationDecl *D - = getPartialSpecializations().FindNodeOrInsertPos(ID, InsertPos); - return D ? D->getMostRecentDeclaration() : 0; + return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs, + InsertPos); } void ClassTemplateDecl::getPartialSpecializations(