diff options
author | dim <dim@FreeBSD.org> | 2013-04-08 18:45:10 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2013-04-08 18:45:10 +0000 |
commit | c72c57c9e9b69944e3e009cd5e209634839581d3 (patch) | |
tree | 4fc2f184c499d106f29a386c452b49e5197bf63d /lib/Sema/SemaTemplateDeduction.cpp | |
parent | 5b20025c30d23d521e12c1f33ec8fa6b821952cd (diff) | |
download | FreeBSD-src-c72c57c9e9b69944e3e009cd5e209634839581d3.zip FreeBSD-src-c72c57c9e9b69944e3e009cd5e209634839581d3.tar.gz |
Vendor import of clang trunk r178860:
http://llvm.org/svn/llvm-project/cfe/trunk@178860
Diffstat (limited to 'lib/Sema/SemaTemplateDeduction.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateDeduction.cpp | 104 |
1 files changed, 47 insertions, 57 deletions
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index bf4533d..f3bbe8a 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -10,18 +10,18 @@ // //===----------------------------------------------------------------------===/ -#include "clang/Sema/Sema.h" -#include "clang/Sema/DeclSpec.h" -#include "clang/Sema/Template.h" #include "clang/Sema/TemplateDeduction.h" +#include "TreeTransform.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" -#include "clang/AST/StmtVisitor.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" +#include "clang/AST/StmtVisitor.h" +#include "clang/Sema/DeclSpec.h" +#include "clang/Sema/Sema.h" +#include "clang/Sema/Template.h" #include "llvm/ADT/SmallBitVector.h" -#include "TreeTransform.h" #include <algorithm> namespace clang { @@ -130,8 +130,7 @@ DeduceTemplateArguments(Sema &S, const TemplateArgument *Params, unsigned NumParams, const TemplateArgument *Args, unsigned NumArgs, TemplateDeductionInfo &Info, - SmallVectorImpl<DeducedTemplateArgument> &Deduced, - bool NumberOfArgumentsMustMatch = true); + SmallVectorImpl<DeducedTemplateArgument> &Deduced); /// \brief If the given expression is of a form that permits the deduction /// of a non-type template parameter, return the declaration of that @@ -482,21 +481,26 @@ DeduceTemplateArguments(Sema &S, return DeduceTemplateArguments(S, TemplateParams, Param->getArgs(), Param->getNumArgs(), SpecArg->getArgs(), SpecArg->getNumArgs(), - Info, Deduced, - /*NumberOfArgumentsMustMatch=*/false); + Info, Deduced); } // If the argument type is a class template specialization, we // perform template argument deduction using its template // arguments. const RecordType *RecordArg = dyn_cast<RecordType>(Arg); - if (!RecordArg) + if (!RecordArg) { + Info.FirstArg = TemplateArgument(QualType(Param, 0)); + Info.SecondArg = TemplateArgument(Arg); return Sema::TDK_NonDeducedMismatch; + } ClassTemplateSpecializationDecl *SpecArg = dyn_cast<ClassTemplateSpecializationDecl>(RecordArg->getDecl()); - if (!SpecArg) + if (!SpecArg) { + Info.FirstArg = TemplateArgument(QualType(Param, 0)); + Info.SecondArg = TemplateArgument(Arg); return Sema::TDK_NonDeducedMismatch; + } // Perform template argument deduction for the template name. if (Sema::TemplateDeductionResult Result @@ -710,7 +714,7 @@ DeduceTemplateArguments(Sema &S, if (NumParams != NumArgs && !(NumParams && isa<PackExpansionType>(Params[NumParams - 1])) && !(NumArgs && isa<PackExpansionType>(Args[NumArgs - 1]))) - return Sema::TDK_NonDeducedMismatch; + return Sema::TDK_MiscellaneousDeductionFailure; // C++0x [temp.deduct.type]p10: // Similarly, if P has a form that contains (T), then each parameter type @@ -727,14 +731,14 @@ DeduceTemplateArguments(Sema &S, // Make sure we have an argument. if (ArgIdx >= NumArgs) - return Sema::TDK_NonDeducedMismatch; + return Sema::TDK_MiscellaneousDeductionFailure; if (isa<PackExpansionType>(Args[ArgIdx])) { // C++0x [temp.deduct.type]p22: // If the original function parameter associated with A is a function // parameter pack and the function parameter associated with P is not // a function parameter pack, then template argument deduction fails. - return Sema::TDK_NonDeducedMismatch; + return Sema::TDK_MiscellaneousDeductionFailure; } if (Sema::TemplateDeductionResult Result @@ -827,7 +831,7 @@ DeduceTemplateArguments(Sema &S, // Make sure we don't have any extra arguments. if (ArgIdx < NumArgs) - return Sema::TDK_NonDeducedMismatch; + return Sema::TDK_MiscellaneousDeductionFailure; return Sema::TDK_Success; } @@ -1749,8 +1753,7 @@ DeduceTemplateArguments(Sema &S, const TemplateArgument *Params, unsigned NumParams, const TemplateArgument *Args, unsigned NumArgs, TemplateDeductionInfo &Info, - SmallVectorImpl<DeducedTemplateArgument> &Deduced, - bool NumberOfArgumentsMustMatch) { + SmallVectorImpl<DeducedTemplateArgument> &Deduced) { // C++0x [temp.deduct.type]p9: // If the template argument list of P contains a pack expansion that is not // the last template argument, the entire template argument list is a @@ -1770,13 +1773,12 @@ DeduceTemplateArguments(Sema &S, // Check whether we have enough arguments. if (!hasTemplateArgumentForDeduction(Args, ArgIdx, NumArgs)) - return NumberOfArgumentsMustMatch? Sema::TDK_NonDeducedMismatch - : Sema::TDK_Success; + return Sema::TDK_Success; if (Args[ArgIdx].isPackExpansion()) { // FIXME: We follow the logic of C++0x [temp.deduct.type]p22 here, // but applied to pack expansions that are template arguments. - return Sema::TDK_NonDeducedMismatch; + return Sema::TDK_MiscellaneousDeductionFailure; } // Perform deduction for this Pi/Ai pair. @@ -1867,11 +1869,6 @@ DeduceTemplateArguments(Sema &S, return Result; } - // If there is an argument remaining, then we had too many arguments. - if (NumberOfArgumentsMustMatch && - hasTemplateArgumentForDeduction(Args, ArgIdx, NumArgs)) - return Sema::TDK_NonDeducedMismatch; - return Sema::TDK_Success; } @@ -2400,7 +2397,7 @@ Sema::SubstituteExplicitTemplateArguments( } CXXThisScopeRAII ThisScope(*this, ThisContext, ThisTypeQuals, - getLangOpts().CPlusPlus0x); + getLangOpts().CPlusPlus11); ResultType = SubstType(Proto->getResultType(), MultiLevelTemplateArgumentList(*ExplicitArgumentList), @@ -2420,15 +2417,10 @@ Sema::SubstituteExplicitTemplateArguments( return TDK_SubstitutionFailure; if (FunctionType) { - *FunctionType = BuildFunctionType(ResultType, - ParamTypes.data(), ParamTypes.size(), - Proto->isVariadic(), - Proto->hasTrailingReturn(), - Proto->getTypeQuals(), - Proto->getRefQualifier(), + *FunctionType = BuildFunctionType(ResultType, ParamTypes, Function->getLocation(), Function->getDeclName(), - Proto->getExtInfo()); + Proto->getExtProtoInfo()); if (FunctionType->isNull() || Trap.hasErrorOccurred()) return TDK_SubstitutionFailure; } @@ -2656,11 +2648,15 @@ Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, if (CurrentInstantiationScope && CurrentInstantiationScope->getPartiallySubstitutedPack(&ExplicitArgs, &NumExplicitArgs) - == Param) + == Param) { Builder.push_back(TemplateArgument(ExplicitArgs, NumExplicitArgs)); - else - Builder.push_back(TemplateArgument::getEmptyPack()); + // Forget the partially-substituted pack; it's substitution is now + // complete. + CurrentInstantiationScope->ResetPartiallySubstitutedPack(); + } else { + Builder.push_back(TemplateArgument::getEmptyPack()); + } continue; } @@ -2884,7 +2880,8 @@ ResolveOverloadForDeduction(Sema &S, TemplateParameterList *TemplateParams, /// described in C++ [temp.deduct.call]. /// /// \returns true if the caller should not attempt to perform any template -/// argument deduction based on this P/A pair. +/// argument deduction based on this P/A pair because the argument is an +/// overloaded function set that could not be resolved. static bool AdjustFunctionParmAndArgTypesForDeduction(Sema &S, TemplateParameterList *TemplateParams, QualType &ParamType, @@ -2900,7 +2897,7 @@ static bool AdjustFunctionParmAndArgTypesForDeduction(Sema &S, if (ParamRefType) { QualType PointeeType = ParamRefType->getPointeeType(); - // If the argument has incomplete array type, try to complete it's type. + // If the argument has incomplete array type, try to complete its type. if (ArgType->isIncompleteArrayType() && !S.RequireCompleteExprType(Arg, 0)) ArgType = Arg->getType(); @@ -2998,8 +2995,8 @@ static bool hasDeducibleTemplateParameters(Sema &S, /// \brief Perform template argument deduction by matching a parameter type /// against a single expression, where the expression is an element of -/// an initializer list that was originally matched against the argument -/// type. +/// an initializer list that was originally matched against a parameter +/// of type \c initializer_list\<ParamType\>. static Sema::TemplateDeductionResult DeduceTemplateArgumentByListElement(Sema &S, TemplateParameterList *TemplateParams, @@ -3028,8 +3025,10 @@ DeduceTemplateArgumentByListElement(Sema &S, // For all other cases, just match by type. QualType ArgType = Arg->getType(); if (AdjustFunctionParmAndArgTypesForDeduction(S, TemplateParams, ParamType, - ArgType, Arg, TDF)) + ArgType, Arg, TDF)) { + Info.Expression = Arg; return Sema::TDK_FailedOverloadResolution; + } return DeduceTemplateArgumentsByTypeMatch(S, TemplateParams, ParamType, ArgType, Info, Deduced, TDF); } @@ -3045,11 +3044,6 @@ DeduceTemplateArgumentByListElement(Sema &S, /// /// \param Args the function call arguments /// -/// \param Name the name of the function being called. This is only significant -/// when the function template is a conversion function template, in which -/// case this routine will also perform template argument deduction based on -/// the function to which -/// /// \param Specialization if template argument deduction was successful, /// this will be set to the function template specialization produced by /// template argument deduction. @@ -3372,7 +3366,7 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, // specialization, template argument deduction fails. if (!ArgFunctionType.isNull() && !Context.hasSameType(ArgFunctionType, Specialization->getType())) - return TDK_NonDeducedMismatch; + return TDK_MiscellaneousDeductionFailure; return TDK_Success; } @@ -3772,15 +3766,15 @@ static bool isAtLeastAsSpecializedAs(Sema &S, // first argument of the free function, which seems to match // existing practice. SmallVector<QualType, 4> Args1; - unsigned Skip1 = !S.getLangOpts().CPlusPlus0x && IsNonStatic2 && !Method1; - if (S.getLangOpts().CPlusPlus0x && IsNonStatic1 && !Method2) + unsigned Skip1 = !S.getLangOpts().CPlusPlus11 && IsNonStatic2 && !Method1; + if (S.getLangOpts().CPlusPlus11 && IsNonStatic1 && !Method2) AddImplicitObjectParameterType(S.Context, Method1, Args1); Args1.insert(Args1.end(), Proto1->arg_type_begin() + Skip1, Proto1->arg_type_end()); SmallVector<QualType, 4> Args2; - Skip2 = !S.getLangOpts().CPlusPlus0x && IsNonStatic1 && !Method2; - if (S.getLangOpts().CPlusPlus0x && IsNonStatic2 && !Method1) + Skip2 = !S.getLangOpts().CPlusPlus11 && IsNonStatic1 && !Method2; + if (S.getLangOpts().CPlusPlus11 && IsNonStatic2 && !Method1) AddImplicitObjectParameterType(S.Context, Method2, Args2); Args2.insert(Args2.end(), Proto2->arg_type_begin() + Skip2, Proto2->arg_type_end()); @@ -3849,7 +3843,7 @@ static bool isAtLeastAsSpecializedAs(Sema &S, unsigned NumParams = std::min(NumCallArguments, std::min(Proto1->getNumArgs(), Proto2->getNumArgs())); - if (S.getLangOpts().CPlusPlus0x && IsNonStatic2 && !IsNonStatic1) + if (S.getLangOpts().CPlusPlus11 && IsNonStatic2 && !IsNonStatic1) ::MarkUsedTemplateParameters(S.Context, Method2->getThisType(S.Context), false, TemplateParams->getDepth(), UsedParameters); @@ -4052,10 +4046,6 @@ static bool isSameTemplate(TemplateDecl *T1, TemplateDecl *T2) { /// in this diagnostic should be unbound, which will correspond to the string /// describing the template arguments for the function template specialization. /// -/// \param Index if non-NULL and the result of this function is non-nULL, -/// receives the index corresponding to the resulting function template -/// specialization. -/// /// \returns the most specialized function template specialization, if /// found. Otherwise, returns SpecEnd. /// @@ -4618,7 +4608,7 @@ Sema::MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, /// call to the given function template. void Sema::MarkDeducedTemplateParameters(ASTContext &Ctx, - FunctionTemplateDecl *FunctionTemplate, + const FunctionTemplateDecl *FunctionTemplate, llvm::SmallBitVector &Deduced) { TemplateParameterList *TemplateParams = FunctionTemplate->getTemplateParameters(); |