diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-02-05 07:33:43 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-02-05 07:33:43 +0000 |
commit | 525f96c0ef39f91abd26b1b4584ba1814e7ebc28 (patch) | |
tree | cc0f56e69af84be05ac59db1ca7e459d05133baa | |
parent | 9da559868fcdd26ac0448a2943cc27af74923eb3 (diff) |
Default function arguments for function template specializations
always come from the primary template, so gather the instantiation
template arguments from the primary template.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95380 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/Sema.h | 3 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 15 | ||||
-rw-r--r-- | test/SemaTemplate/default-expr-arguments.cpp | 7 |
4 files changed, 23 insertions, 5 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 19de095b2a..6a7590997c 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -2959,7 +2959,8 @@ public: // MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D, - const TemplateArgumentList *Innermost = 0); + const TemplateArgumentList *Innermost = 0, + bool RelativeToPrimary = false); /// \brief A template instantiation that is currently in progress. struct ActiveTemplateInstantiation { diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 99714aee36..4e448d8197 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3280,7 +3280,8 @@ Sema::OwningExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc, Expr *UninstExpr = Param->getUninstantiatedDefaultArg(); // Instantiate the expression. - MultiLevelTemplateArgumentList ArgList = getTemplateInstantiationArgs(FD); + MultiLevelTemplateArgumentList ArgList + = getTemplateInstantiationArgs(FD, 0, /*RelativeToPrimary=*/true); InstantiatingTemplate Inst(*this, CallLoc, Param, ArgList.getInnermost().getFlatArgumentList(), diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index b560fad25e..5c5701ac79 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -33,9 +33,15 @@ using namespace clang; /// arguments. /// /// \param Innermost if non-NULL, the innermost template argument list. +/// +/// \param RelativeToPrimary true if we should get the template +/// arguments relative to the primary template, even when we're +/// dealing with a specialization. This is only relevant for function +/// template specializations. MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs(NamedDecl *D, - const TemplateArgumentList *Innermost) { + const TemplateArgumentList *Innermost, + bool RelativeToPrimary) { // Accumulate the set of template argument lists in this structure. MultiLevelTemplateArgumentList Result; @@ -64,8 +70,9 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D, } // Add template arguments from a function template specialization. else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) { - if (Function->getTemplateSpecializationKind() - == TSK_ExplicitSpecialization) + if (!RelativeToPrimary && + Function->getTemplateSpecializationKind() + == TSK_ExplicitSpecialization) break; if (const TemplateArgumentList *TemplateArgs @@ -86,11 +93,13 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D, if (Function->getFriendObjectKind() && Function->getDeclContext()->isFileContext()) { Ctx = Function->getLexicalDeclContext(); + RelativeToPrimary = false; continue; } } Ctx = Ctx->getParent(); + RelativeToPrimary = false; } return Result; diff --git a/test/SemaTemplate/default-expr-arguments.cpp b/test/SemaTemplate/default-expr-arguments.cpp index 131b80cb1f..3da43fa675 100644 --- a/test/SemaTemplate/default-expr-arguments.cpp +++ b/test/SemaTemplate/default-expr-arguments.cpp @@ -177,3 +177,10 @@ namespace PR5810 { X<float> x; // expected-note{{member function}} } } + +template<typename T> void f4(T, int = 17); +template<> void f4<int>(int, int); + +void f4_test(int i) { + f4(i); +} |