diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-10-13 16:30:37 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-10-13 16:30:37 +0000 |
commit | fd056bc86a8b22a9421b5d921bbca276d0f9d0f7 (patch) | |
tree | e70aa9a7122aa2803f39ddd507f7c02bc1f87594 /lib/Sema/SemaTemplateInstantiate.cpp | |
parent | a735b206fdb5c15767a45289e1ffb3b568f70f2b (diff) |
When explicitly specializing a member that is a template, mark the
template as a specialization. For example, this occurs with:
template<typename T>
struct X {
template<typename U> struct Inner { /* ... */ };
};
template<> template<typename T>
struct X<int>::Inner {
T member;
};
We need to treat templates that are member specializations as special
in two contexts:
- When looking for a definition of a member template, we look
through the instantiation chain until we hit the primary template
*or a member specialization*. This allows us to distinguish
between the primary "Inner" definition and the X<int>::Inner
definition, above.
- When computing all of the levels of template arguments needed to
instantiate a member template, don't add template arguments
from contexts outside of the instantiation of a member
specialization, since the user has already manually substituted
those arguments.
Fix up the existing test for p18, which was actually wrong (but we
didn't diagnose it because of our poor handling of member
specializations of templates), and add a new test for member
specializations of templates.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83974 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiate.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index ec00d9805c..65260c8e1e 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -46,15 +46,31 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D) { break; Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); + + // If this class template specialization was instantiated from a + // specialized member that is a class template, we're done. + assert(Spec->getSpecializedTemplate() && "No class template?"); + if (Spec->getSpecializedTemplate()->isMemberSpecialization()) + break; } - // Add template arguments from a function template specialization. else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) { - // FIXME: Check whether this is an explicit specialization. + if (Function->getTemplateSpecializationKind() + == TSK_ExplicitSpecialization) + break; + if (const TemplateArgumentList *TemplateArgs - = Function->getTemplateSpecializationArgs()) + = Function->getTemplateSpecializationArgs()) { + // Add the template arguments for this specialization. Result.addOuterTemplateArguments(TemplateArgs); + // If this function was instantiated from a specialized member that is + // a function template, we're done. + assert(Function->getPrimaryTemplate() && "No function template?"); + if (Function->getPrimaryTemplate()->isMemberSpecialization()) + break; + } + // If this is a friend declaration and it declares an entity at // namespace scope, take arguments from its lexical parent // instead of its semantic parent. @@ -940,9 +956,15 @@ Sema::InstantiateClassTemplateSpecialization( // -- If no matches are found, the instantiation is generated // from the primary template. ClassTemplateDecl *OrigTemplate = Template; - while (OrigTemplate->getInstantiatedFromMemberTemplate()) + while (OrigTemplate->getInstantiatedFromMemberTemplate()) { + // If we've found an explicit specialization of this class template, + // stop here and use that as the pattern. + if (OrigTemplate->isMemberSpecialization()) + break; + OrigTemplate = OrigTemplate->getInstantiatedFromMemberTemplate(); - + } + Pattern = OrigTemplate->getTemplatedDecl(); } |