diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-11-13 23:45:44 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-11-13 23:45:44 +0000 |
commit | 15755cb8399afa702575a21915daf2f6e56b5ac1 (patch) | |
tree | d68adf5545915a0dcf4a142149b1b80178e3da07 /lib/Sema/SemaTemplateDeduction.cpp | |
parent | cad84b7c12564ff37feb66d6d004bb609bea8788 (diff) |
Template argument deduction of a non-type template parameter from a
template argument.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88722 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateDeduction.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateDeduction.cpp | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 17b4e5fe82..fcec654334 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -126,7 +126,6 @@ DeduceNonTypeTemplateArgument(ASTContext &Context, /// from the given type- or value-dependent expression. /// /// \returns true if deduction succeeded, false otherwise. - static Sema::TemplateDeductionResult DeduceNonTypeTemplateArgument(ASTContext &Context, NonTypeTemplateParmDecl *NTTP, @@ -166,6 +165,43 @@ DeduceNonTypeTemplateArgument(ASTContext &Context, return Sema::TDK_Success; } +/// \brief Deduce the value of the given non-type template parameter +/// from the given declaration. +/// +/// \returns true if deduction succeeded, false otherwise. +static Sema::TemplateDeductionResult +DeduceNonTypeTemplateArgument(ASTContext &Context, + NonTypeTemplateParmDecl *NTTP, + Decl *D, + Sema::TemplateDeductionInfo &Info, + llvm::SmallVectorImpl<TemplateArgument> &Deduced) { + assert(NTTP->getDepth() == 0 && + "Cannot deduce non-type template argument with depth > 0"); + + if (Deduced[NTTP->getIndex()].isNull()) { + Deduced[NTTP->getIndex()] = TemplateArgument(D->getCanonicalDecl()); + return Sema::TDK_Success; + } + + if (Deduced[NTTP->getIndex()].getKind() == TemplateArgument::Expression) { + // Okay, we deduced a declaration in one case and a dependent expression + // in another case. + return Sema::TDK_Success; + } + + if (Deduced[NTTP->getIndex()].getKind() == TemplateArgument::Declaration) { + // Compare the declarations for equality + if (Deduced[NTTP->getIndex()].getAsDecl()->getCanonicalDecl() == + D->getCanonicalDecl()) + return Sema::TDK_Success; + + // FIXME: Fill in argument mismatch information + return Sema::TDK_NonDeducedMismatch; + } + + return Sema::TDK_Success; +} + static Sema::TemplateDeductionResult DeduceTemplateArguments(ASTContext &Context, TemplateParameterList *TemplateParams, @@ -847,7 +883,10 @@ DeduceTemplateArguments(ASTContext &Context, if (Arg.getKind() == TemplateArgument::Expression) return DeduceNonTypeTemplateArgument(Context, NTTP, Arg.getAsExpr(), Info, Deduced); - + if (Arg.getKind() == TemplateArgument::Declaration) + return DeduceNonTypeTemplateArgument(Context, NTTP, Arg.getAsDecl(), + Info, Deduced); + assert(false && "Type/value mismatch"); Info.FirstArg = Param; Info.SecondArg = Arg; |