diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-06-05 00:53:49 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-06-05 00:53:49 +0000 |
commit | 199d99192fbcca9f043596c40ead4afab4999dba (patch) | |
tree | 14716988cdd0af1ae955782954af60f098390770 /lib/Sema/SemaTemplateInstantiate.cpp | |
parent | 29b1d07a87a2038ae5b4128a0b534badd728707d (diff) |
Several improvements to template argument deduction:
- Once we have deduced template arguments for a class template partial
specialization, we use exactly those template arguments for instantiating
the definition of the class template partial specialization.
- Added template argument deduction for non-type template parameters.
- Added template argument deduction for dependently-sized array types.
With these changes, we can now implement, e.g., the remove_reference
type trait. Also, Daniel's Ackermann template metaprogram now compiles
properly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72909 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiate.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 0400b4c060..562749e18f 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -833,21 +833,23 @@ Sema::InstantiateClassTemplateSpecialization( // Determine whether any class template partial specializations // match the given template arguments. - llvm::SmallVector<ClassTemplatePartialSpecializationDecl *, 4> Matched; + typedef std::pair<ClassTemplatePartialSpecializationDecl *, + TemplateArgumentList *> MatchResult; + llvm::SmallVector<MatchResult, 4> Matched; for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator Partial = Template->getPartialSpecializations().begin(), PartialEnd = Template->getPartialSpecializations().end(); Partial != PartialEnd; ++Partial) { - if (DeduceTemplateArguments(&*Partial, ClassTemplateSpec->getTemplateArgs())) - Matched.push_back(&*Partial); + if (TemplateArgumentList *Deduced + = DeduceTemplateArguments(&*Partial, + ClassTemplateSpec->getTemplateArgs())) + Matched.push_back(std::make_pair(&*Partial, Deduced)); } if (Matched.size() == 1) { - Pattern = Matched[0]; - // FIXME: set TemplateArgs to the template arguments of the - // partial specialization, instantiated with the deduced template - // arguments. + Pattern = Matched[0].first; + TemplateArgs = Matched[0].second; } else if (Matched.size() > 1) { // FIXME: Implement partial ordering of class template partial // specializations. @@ -860,9 +862,17 @@ Sema::InstantiateClassTemplateSpecialization( ExplicitInstantiation? TSK_ExplicitInstantiation : TSK_ImplicitInstantiation); - return InstantiateClass(ClassTemplateSpec->getLocation(), - ClassTemplateSpec, Pattern, *TemplateArgs, - ExplicitInstantiation); + bool Result = InstantiateClass(ClassTemplateSpec->getLocation(), + ClassTemplateSpec, Pattern, *TemplateArgs, + ExplicitInstantiation); + + for (unsigned I = 0, N = Matched.size(); I != N; ++I) { + // FIXME: Implement TemplateArgumentList::Destroy! + // if (Matched[I].first != Pattern) + // Matched[I].second->Destroy(Context); + } + + return Result; } /// \brief Instantiate the definitions of all of the member of the |