summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaTemplateDeduction.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-12-22 18:55:49 +0000
committerDouglas Gregor <dgregor@apple.com>2010-12-22 18:55:49 +0000
commitd80ea20411809cfccaaf9359e135fe7cb2571474 (patch)
treebab2f56254ead52040bbfd8bc0e97deba2ef640b /clang/lib/Sema/SemaTemplateDeduction.cpp
parent1696f508e2fe95793ca8bb70d78b88023b6b8625 (diff)
downloadbcm5719-llvm-d80ea20411809cfccaaf9359e135fe7cb2571474.tar.gz
bcm5719-llvm-d80ea20411809cfccaaf9359e135fe7cb2571474.zip
When performing template argument deduction where the argument is a
dependent template specialization type, the number of template arguments need not match precisely. Rather than checking the number of arguments eagerly (which does not consider argument packs), let the deduction routine for template argument lists cope with too many/too few arguments. llvm-svn: 122425
Diffstat (limited to 'clang/lib/Sema/SemaTemplateDeduction.cpp')
-rw-r--r--clang/lib/Sema/SemaTemplateDeduction.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 108f2075103..80ba1a3dd69 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -81,7 +81,7 @@ DeduceTemplateArguments(Sema &S,
const TemplateArgument &Param,
const TemplateArgument &Arg,
TemplateDeductionInfo &Info,
- llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced);
+ llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced);
static Sema::TemplateDeductionResult
DeduceTemplateArguments(Sema &S,
@@ -89,7 +89,8 @@ DeduceTemplateArguments(Sema &S,
const TemplateArgument *Params, unsigned NumParams,
const TemplateArgument *Args, unsigned NumArgs,
TemplateDeductionInfo &Info,
- llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced);
+ llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced,
+ bool NumberOfArgumentsMustMatch = true);
/// \brief If the given expression is of a form that permits the deduction
/// of a non-type template parameter, return the declaration of that
@@ -309,14 +310,13 @@ DeduceTemplateArguments(Sema &S,
// Perform template argument deduction on each template
- // argument.
- // FIXME: This "min" function isn't going to work in general. We should
- // probably pass down a flag that allows too few/too many arguments.
- unsigned NumArgs = std::min(SpecArg->getNumArgs(), Param->getNumArgs());
+ // argument. Ignore any missing/extra arguments, since they could be
+ // filled in by default arguments.
return DeduceTemplateArguments(S, TemplateParams,
- Param->getArgs(), NumArgs,
- SpecArg->getArgs(), NumArgs,
- Info, Deduced);
+ Param->getArgs(), Param->getNumArgs(),
+ SpecArg->getArgs(), SpecArg->getNumArgs(),
+ Info, Deduced,
+ /*NumberOfArgumentsMustMatch=*/false);
}
// If the argument type is a class template specialization, we
@@ -953,7 +953,8 @@ DeduceTemplateArguments(Sema &S,
const TemplateArgument *Params, unsigned NumParams,
const TemplateArgument *Args, unsigned NumArgs,
TemplateDeductionInfo &Info,
- llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
+ llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced,
+ bool NumberOfArgumentsMustMatch) {
unsigned ArgIdx = 0, ParamIdx = 0;
for (; hasTemplateArgumentForDeduction(Params, ParamIdx, NumParams);
++ParamIdx) {
@@ -962,7 +963,8 @@ DeduceTemplateArguments(Sema &S,
// Check whether we have enough arguments.
if (!hasTemplateArgumentForDeduction(Args, ArgIdx, NumArgs))
- return Sema::TDK_TooFewArguments;
+ return NumberOfArgumentsMustMatch? Sema::TDK_TooFewArguments
+ : Sema::TDK_Success;
// Perform deduction for this P/A pair.
if (Sema::TemplateDeductionResult Result
@@ -985,7 +987,8 @@ DeduceTemplateArguments(Sema &S,
}
// If there is an argument remaining, then we had too many arguments.
- if (hasTemplateArgumentForDeduction(Args, ArgIdx, NumArgs))
+ if (NumberOfArgumentsMustMatch &&
+ hasTemplateArgumentForDeduction(Args, ArgIdx, NumArgs))
return Sema::TDK_TooManyArguments;
return Sema::TDK_Success;
OpenPOWER on IntegriCloud