diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-12-21 23:17:24 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-12-21 23:17:24 +0000 |
commit | 4b52e25f3b05ab0f9d2492276a52323a50a84fb7 (patch) | |
tree | 5d7475db3666f0c34a3c9381783dec79793760ba /lib/Sema/SemaTemplateDeduction.cpp | |
parent | c78a69dd901f200de958063997946119e366e4d2 (diff) |
When a template-id refers to a single function template, and the
explicitly-specified template arguments are enough to determine the
instantiation, and either template argument deduction fails or is not
performed in that context, we can resolve the template-id down to a
function template specialization (so sayeth C++0x
[temp.arg.explicit]p3). Fixes PR5811.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91852 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateDeduction.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateDeduction.cpp | 91 |
1 files changed, 69 insertions, 22 deletions
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 5434beaef1..11798c468a 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -1506,15 +1506,39 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, ParamType->getAs<PointerType>()->getPointeeType()))) TDF |= TDF_DerivedClass; + // FIXME: C++0x [temp.deduct.call] paragraphs 6-9 deal with function + // pointer parameters. + + if (Context.hasSameUnqualifiedType(ArgType, Context.OverloadTy)) { + // We know that template argument deduction will fail if the argument is + // still an overloaded function. Check whether we can resolve this + // argument as a single function template specialization per + // C++ [temp.arg.explicit]p3. + FunctionDecl *ExplicitSpec + = ResolveSingleFunctionTemplateSpecialization(Args[I]); + Expr *ResolvedArg = 0; + if (ExplicitSpec) + ResolvedArg = FixOverloadedFunctionReference(Args[I], ExplicitSpec); + if (!ExplicitSpec || !ResolvedArg) { + // Template argument deduction fails if we can't resolve the overloaded + // function. + return TDK_FailedOverloadResolution; + } + + // Get the type of the resolved argument. + ArgType = ResolvedArg->getType(); + if (ArgType->isPointerType() || ArgType->isMemberPointerType()) + TDF |= TDF_IgnoreQualifiers; + + ResolvedArg->Destroy(Context); + } + if (TemplateDeductionResult Result = ::DeduceTemplateArguments(Context, TemplateParams, ParamType, ArgType, Info, Deduced, TDF)) return Result; - // FIXME: C++0x [temp.deduct.call] paragraphs 6-9 deal with function - // pointer parameters. - // FIXME: we need to check that the deduced A is the same as A, // modulo the various allowed differences. } @@ -1524,24 +1548,19 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, } /// \brief Deduce template arguments when taking the address of a function -/// template (C++ [temp.deduct.funcaddr]) or matching a +/// template (C++ [temp.deduct.funcaddr]) or matching a specialization to +/// a template. /// /// \param FunctionTemplate the function template for which we are performing /// template argument deduction. /// -/// \param HasExplicitTemplateArgs whether any template arguments were -/// explicitly specified. -/// -/// \param ExplicitTemplateArguments when @p HasExplicitTemplateArgs is true, -/// the explicitly-specified template arguments. -/// -/// \param NumExplicitTemplateArguments when @p HasExplicitTemplateArgs is true, -/// the number of explicitly-specified template arguments in -/// @p ExplicitTemplateArguments. This value may be zero. +/// \param ExplicitTemplateArguments the explicitly-specified template +/// arguments. /// /// \param ArgFunctionType the function type that will be used as the /// "argument" type (A) when performing template argument deduction from the -/// function template's function type. +/// function template's function type. This type may be NULL, if there is no +/// argument type to compare against, in C++0x [temp.arg.explicit]p3. /// /// \param Specialization if template argument deduction was successful, /// this will be set to the function template specialization produced by @@ -1578,14 +1597,16 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, // Trap any errors that might occur. SFINAETrap Trap(*this); - // Deduce template arguments from the function type. - Deduced.resize(TemplateParams->size()); - if (TemplateDeductionResult Result - = ::DeduceTemplateArguments(Context, TemplateParams, - FunctionType, ArgFunctionType, Info, - Deduced, 0)) - return Result; - + if (!ArgFunctionType.isNull()) { + // Deduce template arguments from the function type. + Deduced.resize(TemplateParams->size()); + if (TemplateDeductionResult Result + = ::DeduceTemplateArguments(Context, TemplateParams, + FunctionType, ArgFunctionType, Info, + Deduced, 0)) + return Result; + } + return FinishTemplateArgumentDeduction(FunctionTemplate, Deduced, Specialization, Info); } @@ -1694,6 +1715,32 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, return Result; } +/// \brief Deduce template arguments for a function template when there is +/// nothing to deduce against (C++0x [temp.arg.explicit]p3). +/// +/// \param FunctionTemplate the function template for which we are performing +/// template argument deduction. +/// +/// \param ExplicitTemplateArguments the explicitly-specified template +/// arguments. +/// +/// \param Specialization if template argument deduction was successful, +/// this will be set to the function template specialization produced by +/// template argument deduction. +/// +/// \param Info the argument will be updated to provide additional information +/// about template argument deduction. +/// +/// \returns the result of template argument deduction. +Sema::TemplateDeductionResult +Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, + const TemplateArgumentListInfo *ExplicitTemplateArgs, + FunctionDecl *&Specialization, + TemplateDeductionInfo &Info) { + return DeduceTemplateArguments(FunctionTemplate, ExplicitTemplateArgs, + QualType(), Specialization, Info); +} + /// \brief Stores the result of comparing the qualifiers of two types. enum DeductionQualifierComparison { NeitherMoreQualified = 0, |