diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-09-24 23:14:47 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-09-24 23:14:47 +0000 |
commit | b9aa6b214c8fbc3e081dde575eef1f0913d48bdc (patch) | |
tree | 77bf753a91b1d025823f3adc0a285c0d973beab9 /lib/AST/Decl.cpp | |
parent | 119fa68eb1394a2653bb651dc5c1cf294cbbdbda (diff) |
WIP implementation of explicit function template specialization. This
first implementation recognizes when a function declaration is an
explicit function template specialization (based on the presence of a
template<> header), performs template argument deduction + ambiguity
resolution to determine which template is being specialized, and hooks
There are many caveats here:
- We completely and totally drop any explicitly-specified template
arguments on the floor
- We don't diagnose any of the extra semantic things that we should
diagnose.
- I haven't looked to see that we're getting the right linkage for
explicit specializations
On a happy note, this silences a bunch of errors that show up in
libstdc++'s <iostream>, although Clang still can't get through the
entire header.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82728 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r-- | lib/AST/Decl.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 1a7aaac6f7..25d3d44cc8 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -689,7 +689,10 @@ void FunctionDecl::setFunctionTemplateSpecialization(ASTContext &Context, FunctionTemplateDecl *Template, const TemplateArgumentList *TemplateArgs, - void *InsertPos) { + void *InsertPos, + TemplateSpecializationKind TSK) { + assert(TSK != TSK_Undeclared && + "Must specify the type of function template specialization"); FunctionTemplateSpecializationInfo *Info = TemplateOrSpecialization.dyn_cast<FunctionTemplateSpecializationInfo*>(); if (!Info) @@ -697,13 +700,24 @@ FunctionDecl::setFunctionTemplateSpecialization(ASTContext &Context, Info->Function = this; Info->Template.setPointer(Template); - Info->Template.setInt(TSK_ImplicitInstantiation - 1); + Info->Template.setInt(TSK - 1); Info->TemplateArguments = TemplateArgs; TemplateOrSpecialization = Info; // Insert this function template specialization into the set of known - // function template specialiations. - Template->getSpecializations().InsertNode(Info, InsertPos); + // function template specializations. + if (InsertPos) + Template->getSpecializations().InsertNode(Info, InsertPos); + else { + // Try to insert the new node. If there is an existing node, remove it + // first. + FunctionTemplateSpecializationInfo *Existing + = Template->getSpecializations().GetOrInsertNode(Info); + if (Existing) { + Template->getSpecializations().RemoveNode(Existing); + Template->getSpecializations().GetOrInsertNode(Info); + } + } } TemplateSpecializationKind FunctionDecl::getTemplateSpecializationKind() const { |