diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2011-01-27 07:10:08 +0000 |
---|---|---|
committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2011-01-27 07:10:08 +0000 |
commit | dfbb02a16ac8c764b5ba1742450513d6212d2f9f (patch) | |
tree | a66b32d33dd38cbc65bdf9d7d6463e98e17f94ac /lib/Sema/SemaTemplateDeduction.cpp | |
parent | 0099530a2288df7c2140dd8992b7310b9f6930a9 (diff) |
Fix whitespace.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124364 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateDeduction.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateDeduction.cpp | 784 |
1 files changed, 392 insertions, 392 deletions
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 1cad33360f..5a0359c5fd 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -51,7 +51,7 @@ namespace clang { /// may apply. TDF_SkipNonDependent = 0x08, /// \brief Whether we are performing template argument deduction for - /// parameters and arguments in a top-level template argument + /// parameters and arguments in a top-level template argument TDF_TopLevelParameterTypeList = 0x10 }; } @@ -90,21 +90,21 @@ DeduceTemplateArguments(Sema &S, /// \brief Whether template argument deduction for two reference parameters /// resulted in the argument type, parameter type, or neither type being more /// qualified than the other. -enum DeductionQualifierComparison { - NeitherMoreQualified = 0, - ParamMoreQualified, - ArgMoreQualified +enum DeductionQualifierComparison { + NeitherMoreQualified = 0, + ParamMoreQualified, + ArgMoreQualified }; /// \brief Stores the result of comparing two reference parameters while /// performing template argument deduction for partial ordering of function -/// templates. +/// templates. struct RefParamPartialOrderingComparison { /// \brief Whether the parameter type is an rvalue reference type. bool ParamIsRvalueRef; /// \brief Whether the argument type is an rvalue reference type. bool ArgIsRvalueRef; - + /// \brief Whether the parameter or argument (or neither) is more qualified. DeductionQualifierComparison Qualifiers; }; @@ -150,12 +150,12 @@ static NonTypeTemplateParmDecl *getDeducedParameterFromExpr(Expr *E) { static bool isSameDeclaration(Decl *X, Decl *Y) { if (!X || !Y) return !X && !Y; - + if (NamedDecl *NX = dyn_cast<NamedDecl>(X)) X = NX->getUnderlyingDecl(); if (NamedDecl *NY = dyn_cast<NamedDecl>(Y)) Y = NY->getUnderlyingDecl(); - + return X->getCanonicalDecl() == Y->getCanonicalDecl(); } @@ -163,7 +163,7 @@ static bool isSameDeclaration(Decl *X, Decl *Y) { /// /// \returns The deduced template argument, or a NULL template argument if /// the deduced template arguments were incompatible. -static DeducedTemplateArgument +static DeducedTemplateArgument checkDeducedTemplateArguments(ASTContext &Context, const DeducedTemplateArgument &X, const DeducedTemplateArgument &Y) { @@ -171,7 +171,7 @@ checkDeducedTemplateArguments(ASTContext &Context, if (X.isNull()) return Y; if (Y.isNull()) - return X; + return X; switch (X.getKind()) { case TemplateArgument::Null: @@ -182,9 +182,9 @@ checkDeducedTemplateArguments(ASTContext &Context, if (Y.getKind() == TemplateArgument::Type && Context.hasSameType(X.getAsType(), Y.getAsType())) return X; - + return DeducedTemplateArgument(); - + case TemplateArgument::Integral: // If we deduced a constant in one case and either a dependent expression or // declaration in another case, keep the integral constant. @@ -193,39 +193,39 @@ checkDeducedTemplateArguments(ASTContext &Context, Y.getKind() == TemplateArgument::Declaration || (Y.getKind() == TemplateArgument::Integral && hasSameExtendedValue(*X.getAsIntegral(), *Y.getAsIntegral()))) - return DeducedTemplateArgument(X, + return DeducedTemplateArgument(X, X.wasDeducedFromArrayBound() && Y.wasDeducedFromArrayBound()); // All other combinations are incompatible. return DeducedTemplateArgument(); - + case TemplateArgument::Template: if (Y.getKind() == TemplateArgument::Template && Context.hasSameTemplateName(X.getAsTemplate(), Y.getAsTemplate())) return X; - + // All other combinations are incompatible. - return DeducedTemplateArgument(); + return DeducedTemplateArgument(); case TemplateArgument::TemplateExpansion: if (Y.getKind() == TemplateArgument::TemplateExpansion && - Context.hasSameTemplateName(X.getAsTemplateOrTemplatePattern(), + Context.hasSameTemplateName(X.getAsTemplateOrTemplatePattern(), Y.getAsTemplateOrTemplatePattern())) return X; - + // All other combinations are incompatible. - return DeducedTemplateArgument(); + return DeducedTemplateArgument(); case TemplateArgument::Expression: - // If we deduced a dependent expression in one case and either an integral - // constant or a declaration in another case, keep the integral constant + // If we deduced a dependent expression in one case and either an integral + // constant or a declaration in another case, keep the integral constant // or declaration. if (Y.getKind() == TemplateArgument::Integral || Y.getKind() == TemplateArgument::Declaration) return DeducedTemplateArgument(Y, X.wasDeducedFromArrayBound() && Y.wasDeducedFromArrayBound()); - + if (Y.getKind() == TemplateArgument::Expression) { // Compare the expressions for equality llvm::FoldingSetNodeID ID1, ID2; @@ -234,49 +234,49 @@ checkDeducedTemplateArguments(ASTContext &Context, if (ID1 == ID2) return X; } - + // All other combinations are incompatible. return DeducedTemplateArgument(); - + case TemplateArgument::Declaration: // If we deduced a declaration and a dependent expression, keep the // declaration. if (Y.getKind() == TemplateArgument::Expression) return X; - + // If we deduced a declaration and an integral constant, keep the // integral constant. if (Y.getKind() == TemplateArgument::Integral) return Y; - + // If we deduced two declarations, make sure they they refer to the // same declaration. if (Y.getKind() == TemplateArgument::Declaration && isSameDeclaration(X.getAsDecl(), Y.getAsDecl())) return X; - + // All other combinations are incompatible. return DeducedTemplateArgument(); - + case TemplateArgument::Pack: if (Y.getKind() != TemplateArgument::Pack || X.pack_size() != Y.pack_size()) return DeducedTemplateArgument(); - - for (TemplateArgument::pack_iterator XA = X.pack_begin(), + + for (TemplateArgument::pack_iterator XA = X.pack_begin(), XAEnd = X.pack_end(), YA = Y.pack_begin(); XA != XAEnd; ++XA, ++YA) { - if (checkDeducedTemplateArguments(Context, - DeducedTemplateArgument(*XA, X.wasDeducedFromArrayBound()), + if (checkDeducedTemplateArguments(Context, + DeducedTemplateArgument(*XA, X.wasDeducedFromArrayBound()), DeducedTemplateArgument(*YA, Y.wasDeducedFromArrayBound())) .isNull()) return DeducedTemplateArgument(); } - + return X; } - + return DeducedTemplateArgument(); } @@ -293,16 +293,16 @@ DeduceNonTypeTemplateArgument(Sema &S, "Cannot deduce non-type template argument with depth > 0"); DeducedTemplateArgument NewDeduced(Value, ValueType, DeducedFromArrayBound); - DeducedTemplateArgument Result = checkDeducedTemplateArguments(S.Context, + DeducedTemplateArgument Result = checkDeducedTemplateArguments(S.Context, Deduced[NTTP->getIndex()], NewDeduced); if (Result.isNull()) { Info.Param = NTTP; Info.FirstArg = Deduced[NTTP->getIndex()]; Info.SecondArg = NewDeduced; - return Sema::TDK_Inconsistent; + return Sema::TDK_Inconsistent; } - + Deduced[NTTP->getIndex()] = Result; return Sema::TDK_Success; } @@ -323,17 +323,17 @@ DeduceNonTypeTemplateArgument(Sema &S, "Expression template argument must be type- or value-dependent."); DeducedTemplateArgument NewDeduced(Value); - DeducedTemplateArgument Result = checkDeducedTemplateArguments(S.Context, - Deduced[NTTP->getIndex()], + DeducedTemplateArgument Result = checkDeducedTemplateArguments(S.Context, + Deduced[NTTP->getIndex()], NewDeduced); - + if (Result.isNull()) { Info.Param = NTTP; Info.FirstArg = Deduced[NTTP->getIndex()]; Info.SecondArg = NewDeduced; - return Sema::TDK_Inconsistent; + return Sema::TDK_Inconsistent; } - + Deduced[NTTP->getIndex()] = Result; return Sema::TDK_Success; } @@ -350,18 +350,18 @@ DeduceNonTypeTemplateArgument(Sema &S, llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced) { assert(NTTP->getDepth() == 0 && "Cannot deduce non-type template argument with depth > 0"); - + DeducedTemplateArgument NewDeduced(D? D->getCanonicalDecl() : 0); - DeducedTemplateArgument Result = checkDeducedTemplateArguments(S.Context, + DeducedTemplateArgument Result = checkDeducedTemplateArguments(S.Context, Deduced[NTTP->getIndex()], NewDeduced); if (Result.isNull()) { Info.Param = NTTP; Info.FirstArg = Deduced[NTTP->getIndex()]; Info.SecondArg = NewDeduced; - return Sema::TDK_Inconsistent; + return Sema::TDK_Inconsistent; } - + Deduced[NTTP->getIndex()] = Result; return Sema::TDK_Success; } @@ -379,28 +379,28 @@ DeduceTemplateArguments(Sema &S, // so there is nothing that we can deduce. return Sema::TDK_Success; } - + if (TemplateTemplateParmDecl *TempParam = dyn_cast<TemplateTemplateParmDecl>(ParamDecl)) { DeducedTemplateArgument NewDeduced(S.Context.getCanonicalTemplateName(Arg)); - DeducedTemplateArgument Result = checkDeducedTemplateArguments(S.Context, + DeducedTemplateArgument Result = checkDeducedTemplateArguments(S.Context, Deduced[TempParam->getIndex()], NewDeduced); if (Result.isNull()) { Info.Param = TempParam; Info.FirstArg = Deduced[TempParam->getIndex()]; Info.SecondArg = NewDeduced; - return Sema::TDK_Inconsistent; + return Sema::TDK_Inconsistent; } - + Deduced[TempParam->getIndex()] = Result; - return Sema::TDK_Success; + return Sema::TDK_Success; } - + // Verify that the two template names are equivalent. if (S.Context.hasSameTemplateName(Param, Arg)) return Sema::TDK_Success; - + // Mismatch of non-dependent template parameter to argument. Info.FirstArg = TemplateArgument(Param); Info.SecondArg = TemplateArgument(Arg); @@ -449,8 +449,8 @@ DeduceTemplateArguments(Sema &S, // Perform template argument deduction on each template // argument. Ignore any missing/extra arguments, since they could be // filled in by default arguments. - return DeduceTemplateArguments(S, TemplateParams, - Param->getArgs(), Param->getNumArgs(), + return DeduceTemplateArguments(S, TemplateParams, + Param->getArgs(), Param->getNumArgs(), SpecArg->getArgs(), SpecArg->getNumArgs(), Info, Deduced, /*NumberOfArgumentsMustMatch=*/false); @@ -478,7 +478,7 @@ DeduceTemplateArguments(Sema &S, return Result; // Perform template argument deduction for the template arguments. - return DeduceTemplateArguments(S, TemplateParams, + return DeduceTemplateArguments(S, TemplateParams, Param->getArgs(), Param->getNumArgs(), SpecArg->getTemplateArgs().data(), SpecArg->getTemplateArgs().size(), @@ -510,25 +510,25 @@ static bool IsPossiblyOpaquelyQualifiedType(QualType T) { } /// \brief Retrieve the depth and index of a template parameter. -static std::pair<unsigned, unsigned> +static std::pair<unsigned, unsigned> getDepthAndIndex(NamedDecl *ND) { if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(ND)) return std::make_pair(TTP->getDepth(), TTP->getIndex()); - + if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(ND)) return std::make_pair(NTTP->getDepth(), NTTP->getIndex()); - + TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(ND); return std::make_pair(TTP->getDepth(), TTP->getIndex()); } /// \brief Retrieve the depth and index of an unexpanded parameter pack. -static std::pair<unsigned, unsigned> +static std::pair<unsigned, unsigned> getDepthAndIndex(UnexpandedParameterPack UPP) { if (const TemplateTypeParmType *TTP = UPP.first.dyn_cast<const TemplateTypeParmType *>()) return std::make_pair(TTP->getDepth(), TTP->getIndex()); - + return getDepthAndIndex(UPP.first.get<NamedDecl *>()); } @@ -539,16 +539,16 @@ static TemplateParameter makeTemplateParameter(Decl *D) { return TemplateParameter(TTP); else if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) return TemplateParameter(NTTP); - + return TemplateParameter(cast<TemplateTemplateParmDecl>(D)); } /// \brief Prepare to perform template argument deduction for all of the /// arguments in a set of argument packs. -static void PrepareArgumentPackDeduction(Sema &S, - llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced, +static void PrepareArgumentPackDeduction(Sema &S, + llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced, const llvm::SmallVectorImpl<unsigned> &PackIndices, - llvm::SmallVectorImpl<DeducedTemplateArgument> &SavedPacks, + llvm::SmallVectorImpl<DeducedTemplateArgument> &SavedPacks, llvm::SmallVectorImpl< llvm::SmallVector<DeducedTemplateArgument, 4> > &NewlyDeducedPacks) { // Save the deduced template arguments for each parameter pack expanded @@ -557,18 +557,18 @@ static void PrepareArgumentPackDeduction(Sema &S, // Save the previously-deduced argument pack, then clear it out so that we // can deduce a new argument pack. SavedPacks[I] = Deduced[PackIndices[I]]; - Deduced[PackIndices[I]] = TemplateArgument(); - + Deduced[PackIndices[I]] = TemplateArgument(); + // If the template arugment pack was explicitly specified, add that to // the set of deduced arguments. const TemplateArgument *ExplicitArgs; unsigned NumExplicitArgs; - if (NamedDecl *PartiallySubstitutedPack + if (NamedDecl *PartiallySubstitutedPack = S.CurrentInstantiationScope->getPartiallySubstitutedPack( &ExplicitArgs, &NumExplicitArgs)) { if (getDepthAndIndex(PartiallySubstitutedPack).second == PackIndices[I]) - NewlyDeducedPacks[I].append(ExplicitArgs, + NewlyDeducedPacks[I].append(ExplicitArgs, ExplicitArgs + NumExplicitArgs); } } @@ -581,9 +581,9 @@ static Sema::TemplateDeductionResult FinishArgumentPackDeduction(Sema &S, TemplateParameterList *TemplateParams, bool HasAnyArguments, - llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced, + llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced, const llvm::SmallVectorImpl<unsigned> &PackIndices, - llvm::SmallVectorImpl<DeducedTemplateArgument> &SavedPacks, + llvm::SmallVectorImpl<DeducedTemplateArgument> &SavedPacks, llvm::SmallVectorImpl< llvm::SmallVector<DeducedTemplateArgument, 4> > &NewlyDeducedPacks, TemplateDeductionInfo &Info) { @@ -596,9 +596,9 @@ FinishArgumentPackDeduction(Sema &S, Deduced[PackIndices[I]] = SavedPacks[I]; continue; } - + DeducedTemplateArgument NewPack; - + if (NewlyDeducedPacks[I].empty()) { // If we deduced an empty argument pack, create it now. NewPack = DeducedTemplateArgument(TemplateArgument(0, 0)); @@ -610,9 +610,9 @@ FinishArgumentPackDeduction(Sema &S, NewPack = DeducedTemplateArgument(TemplateArgument(ArgumentPack, NewlyDeducedPacks[I].size()), - NewlyDeducedPacks[I][0].wasDeducedFromArrayBound()); + NewlyDeducedPacks[I][0].wasDeducedFromArrayBound()); } - + DeducedTemplateArgument Result = checkDeducedTemplateArguments(S.Context, SavedPacks[I], NewPack); if (Result.isNull()) { @@ -622,16 +622,16 @@ FinishArgumentPackDeduction(Sema &S, Info.SecondArg = NewPack; return Sema::TDK_Inconsistent; } - + Deduced[PackIndices[I]] = Result; } - + return Sema::TDK_Success; } /// \brief Deduce the template arguments by comparing the list of parameter -/// types to the list of argument types, as in the parameter-type-lists of -/// function types (C++ [temp.deduct.type]p10). +/// types to the list of argument types, as in the parameter-type-lists of +/// function types (C++ [temp.deduct.type]p10). /// /// \param S The semantic analysis object within which we are deducing /// @@ -653,7 +653,7 @@ FinishArgumentPackDeduction(Sema &S, /// how template argument deduction is performed. /// /// \param PartialOrdering If true, we are performing template argument -/// deduction for during partial ordering for a call +/// deduction for during partial ordering for a call /// (C++0x [temp.deduct.partial]). /// /// \param RefParamComparisons If we're performing template argument deduction @@ -678,24 +678,24 @@ DeduceTemplateArguments(Sema &S, !(NumParams && isa<PackExpansionType>(Params[NumParams - 1])) && !(NumArgs && isa<PackExpansionType>(Args[NumArgs - 1]))) return Sema::TDK_NonDeducedMismatch; - + // C++0x [temp.deduct.type]p10: - // Similarly, if P has a form that contains (T), then each parameter type - // Pi of the respective parameter-type- list of P is compared with the - // corresponding parameter type Ai of the corresponding parameter-type-list - // of A. [...] + // Similarly, if P has a form that contains (T), then each parameter type + // Pi of the respective parameter-type- list of P is compared with the + // corresponding parameter type Ai of the corresponding parameter-type-list + // of A. [...] unsigned ArgIdx = 0, ParamIdx = 0; for (; ParamIdx != NumParams; ++ParamIdx) { // Check argument types. - const PackExpansionType *Expansion + const PackExpansionType *Expansion = dyn_cast<PackExpansionType>(Params[ParamIdx]); if (!Expansion) { // Simple case: compare the parameter and argument types at this point. - + // Make sure we have an argument. if (ArgIdx >= NumArgs) return Sema::TDK_NonDeducedMismatch; - + if (isa<PackExpansionType>(Args[ArgIdx])) { // C++0x [temp.deduct.type]p22: // If the original function parameter associated with A is a function @@ -703,7 +703,7 @@ DeduceTemplateArguments(Sema &S, // a function parameter pack, then template argument deduction fails. return Sema::TDK_NonDeducedMismatch; } - + if (Sema::TemplateDeductionResult Result = DeduceTemplateArguments(S, TemplateParams, Params[ParamIdx], @@ -712,25 +712,25 @@ DeduceTemplateArguments(Sema &S, PartialOrdering, RefParamComparisons)) return Result; - + ++ArgIdx; continue; } - + // C++0x [temp.deduct.type]p5: // The non-deduced contexts are: - // - A function parameter pack that does not occur at the end of the + // - A function parameter pack that does not occur at the end of the // parameter-declaration-clause. if (ParamIdx + 1 < NumParams) return Sema::TDK_Success; // C++0x [temp.deduct.type]p10: - // If the parameter-declaration corresponding to Pi is a function + // If the parameter-declaration corresponding to Pi is a function // parameter pack, then the type of its declarator- id is compared with - // each remaining parameter type in the parameter-type-list of A. Each + // each remaining parameter type in the parameter-type-list of A. Each // comparison deduces template arguments for subsequent positions in the // template parameter packs expanded by the function parameter pack. - + // Compute the set of template parameter indices that correspond to // parameter packs expanded by the pack expansion. llvm::SmallVector<unsigned, 2> PackIndices; @@ -751,26 +751,26 @@ DeduceTemplateArguments(Sema &S, assert(!PackIndices.empty() && "Pack expansion without unexpanded packs?"); // Keep track of the deduced template arguments for each parameter pack - // expanded by this pack expansion (the outer index) and for each + // expanded by this pack expansion (the outer index) and for each // template argument (the inner SmallVectors). llvm::SmallVector<llvm::SmallVector<DeducedTemplateArgument, 4>, 2> NewlyDeducedPacks(PackIndices.size()); - llvm::SmallVector<DeducedTemplateArgument, 2> + llvm::SmallVector<DeducedTemplateArgument, 2> SavedPacks(PackIndices.size()); - PrepareArgumentPackDeduction(S, Deduced, PackIndices, SavedPacks, + PrepareArgumentPackDeduction(S, Deduced, PackIndices, SavedPacks, NewlyDeducedPacks); - + bool HasAnyArguments = false; for (; ArgIdx < NumArgs; ++ArgIdx) { HasAnyArguments = true; - + // Deduce template arguments from the pattern. - if (Sema::TemplateDeductionResult Result + if (Sema::TemplateDeductionResult Result = DeduceTemplateArguments(S, TemplateParams, Pattern, Args[ArgIdx], Info, Deduced, TDF, PartialOrdering, RefParamComparisons)) return Result; - + // Capture the deduced template arguments for each parameter pack expanded // by this pack expansion, add them to the list of arguments we've deduced // for that pack, then clear out the deduced argument. @@ -782,20 +782,20 @@ DeduceTemplateArguments(Sema &S, } } } - + // Build argument packs for each of the parameter packs expanded by this // pack expansion. if (Sema::TemplateDeductionResult Result - = FinishArgumentPackDeduction(S, TemplateParams, HasAnyArguments, + = FinishArgumentPackDeduction(S, TemplateParams, HasAnyArguments, Deduced, PackIndices, SavedPacks, NewlyDeducedPacks, Info)) - return Result; + return Result; } - + // Make sure we don't have any extra arguments. if (ArgIdx < NumArgs) return Sema::TDK_NonDeducedMismatch; - + return Sema::TDK_Success; } @@ -841,34 +841,34 @@ DeduceTemplateArguments(Sema &S, QualType Arg = S.Context.getCanonicalType(ArgIn); // If the argument type is a pack expansion, look at its pattern. - // This isn't explicitly called out + // This isn't explicitly called out if (const PackExpansionType *ArgExpansion = dyn_cast<PackExpansionType>(Arg)) Arg = ArgExpansion->getPattern(); - + if (PartialOrdering) { // C++0x [temp.deduct.partial]p5: - // Before the partial ordering is done, certain transformations are - // performed on the types used for partial ordering: - // - If P is a reference type, P is replaced by the type referred to. + // Before the partial ordering is done, certain transformations are + // performed on the types used for partial ordering: + // - If P is a reference type, P is replaced by the type referred to. const ReferenceType *ParamRef = Param->getAs<ReferenceType>(); if (ParamRef) Param = ParamRef->getPointeeType(); - + // - If A is a reference type, A is replaced by the type referred to. const ReferenceType *ArgRef = Arg->getAs<ReferenceType>(); if (ArgRef) Arg = ArgRef->getPointeeType(); - + if (RefParamComparisons && ParamRef && ArgRef) { // C++0x [temp.deduct.partial]p6: - // If both P and A were reference types (before being replaced with the - // type referred to above), determine which of the two types (if any) is + // If both P and A were reference types (before being replaced with the + // type referred to above), determine which of the two types (if any) is // more cv-qualified than the other; otherwise the types are considered - // to be equally cv-qualified for partial ordering purposes. The result + // to be equally cv-qualified for partial ordering purposes. The result // of this determination will be used below. // - // We save this information for later, using it only when deduction + // We save this information for later, using it only when deduction // succeeds in both directions. RefParamPartialOrderingComparison Comparison; Comparison.ParamIsRvalueRef = ParamRef->getAs<RValueReferenceType>(); @@ -880,13 +880,13 @@ DeduceTemplateArguments(Sema &S, Comparison.Qualifiers = ArgMoreQualified; RefParamComparisons->push_back(Comparison); } - + // C++0x [temp.deduct.partial]p7: // Remove any top-level cv-qualifiers: - // - If P is a cv-qualified type, P is replaced by the cv-unqualified + // - If P is a cv-qualified type, P is replaced by the cv-unqualified // version of P. Param = Param.getUnqualifiedType(); - // - If A is a cv-qualified type, A is replaced by the cv-unqualified + // - If A is a cv-qualified type, A is replaced by the cv-unqualified // version of A. Arg = Arg.getUnqualifiedType(); } else { @@ -901,21 +901,21 @@ DeduceTemplateArguments(Sema &S, Arg.getCVRQualifiers()); Param = S.Context.getQualifiedType(UnqualParam, Quals); } - + if ((TDF & TDF_TopLevelParameterTypeList) && !Param->isFunctionType()) { // C++0x [temp.deduct.type]p10: // If P and A are function types that originated from deduction when // taking the address of a function template (14.8.2.2) or when deducing // template arguments from a function declaration (14.8.2.6) and Pi and - // Ai are parameters of the top-level parameter-type-list of P and A, - // respectively, Pi is adjusted if it is an rvalue reference to a - // cv-unqualified template parameter and Ai is an lvalue reference, in - // which case the type of Pi is changed to be the template parameter + // Ai are parameters of the top-level parameter-type-list of P and A, + // respectively, Pi is adjusted if it is an rvalue reference to a + // cv-unqualified template parameter and Ai is an lvalue reference, in + // which case the type of Pi is changed to be the template parameter // type (i.e., T&& is changed to simply T). [ Note: As a result, when // Pi is T&& and Ai is X&, the adjusted Pi will be T, causing T to be // deduced as X&. - end note ] TDF &= ~TDF_TopLevelParameterTypeList; - + if (const RValueReferenceType *ParamRef = Param->getAs<RValueReferenceType>()) { if (isa<TemplateTypeParmType>(ParamRef->getPointeeType()) && @@ -925,12 +925,12 @@ DeduceTemplateArguments(Sema &S, } } } - + // If the parameter type is not dependent, there is nothing to deduce. if (!Param->isDependentType()) { if (!(TDF & TDF_SkipNonDependent) && Param != Arg) return Sema::TDK_NonDeducedMismatch; - + return Sema::TDK_Success; } @@ -977,18 +977,18 @@ DeduceTemplateArguments(Sema &S, DeducedType = S.Context.getCanonicalType(DeducedType); DeducedTemplateArgument NewDeduced(DeducedType); - DeducedTemplateArgument Result = checkDeducedTemplateArguments(S.Context, + DeducedTemplateArgument Result = checkDeducedTemplateArguments(S.Context, Deduced[Index], NewDeduced); if (Result.isNull()) { Info.Param = cast<TemplateTypeParmDecl>(TemplateParams->getParam(Index)); Info.FirstArg = Deduced[Index]; Info.SecondArg = NewDeduced; - return Sema::TDK_Inconsistent; + return Sema::TDK_Inconsistent; } - + Deduced[Index] = Result; - return Sema::TDK_Success; + return Sema::TDK_Success; } // Set up the template argument deduction information for a failure. @@ -1125,7 +1125,7 @@ DeduceTemplateArguments(Sema &S, if (const ConstantArrayType *ConstantArrayArg = dyn_cast<ConstantArrayType>(ArrayArg)) { llvm::APSInt Size(ConstantArrayArg->getSize()); - return DeduceNonTypeTemplateArgument(S, NTTP, Size, + return DeduceNonTypeTemplateArgument(S, NTTP, Size, S.Context.getSizeType(), /*ArrayBound=*/true, Info, Deduced); @@ -1154,9 +1154,9 @@ DeduceTemplateArguments(Sema &S, const FunctionProtoType *FunctionProtoParam = cast<FunctionProtoType>(Param); - if (FunctionProtoParam->getTypeQuals() + if (FunctionProtoParam->getTypeQuals() != FunctionProtoArg->getTypeQuals() || - FunctionProtoParam->getRefQualifier() + FunctionProtoParam->getRefQualifier() != FunctionProtoArg->getRefQualifier() || FunctionProtoParam->isVariadic() != FunctionProtoArg->isVariadic()) return Sema::TDK_NonDeducedMismatch; @@ -1347,7 +1347,7 @@ DeduceTemplateArguments(Sema &S, // partial ordering. if (Arg.isPackExpansion()) Arg = Arg.getPackExpansionPattern(); - + switch (Param.getKind()) { case TemplateArgument::Null: assert(false && "Null template argument in parameter list"); @@ -1363,7 +1363,7 @@ DeduceTemplateArguments(Sema &S, case TemplateArgument::Template: if (Arg.getKind() == TemplateArgument::Template) - return DeduceTemplateArguments(S, TemplateParams, + return DeduceTemplateArguments(S, TemplateParams, Param.getAsTemplate(), Arg.getAsTemplate(), Info, Deduced); Info.FirstArg = Param; @@ -1373,13 +1373,13 @@ DeduceTemplateArguments(Sema &S, case TemplateArgument::TemplateExpansion: llvm_unreachable("caller should handle pack expansions"); break; - + case TemplateArgument::Declaration: if (Arg.getKind() == TemplateArgument::Declaration && Param.getAsDecl()->getCanonicalDecl() == Arg.getAsDecl()->getCanonicalDecl()) return Sema::TDK_Success; - + Info.FirstArg = Param; Info.SecondArg = Arg; return Sema::TDK_NonDeducedMismatch; @@ -1419,7 +1419,7 @@ DeduceTemplateArguments(Sema &S, if (Arg.getKind() == TemplateArgument::Declaration) return DeduceNonTypeTemplateArgument(S, NTTP, Arg.getAsDecl(), Info, Deduced); - + Info.FirstArg = Param; Info.SecondArg = Arg; return Sema::TDK_NonDeducedMismatch; @@ -1443,12 +1443,12 @@ DeduceTemplateArguments(Sema &S, /// /// \returns true if there is another template argument (which will be at /// \c Args[ArgIdx]), false otherwise. -static bool hasTemplateArgumentForDeduction(const TemplateArgument *&Args, +static bool hasTemplateArgumentForDeduction(const TemplateArgument *&Args, unsigned &ArgIdx, unsigned &NumArgs) { if (ArgIdx == NumArgs) return false; - + const TemplateArgument &Arg = Args[ArgIdx]; if (Arg.getKind() != TemplateArgument::Pack) return true; @@ -1467,7 +1467,7 @@ static bool hasPackExpansionBeforeEnd(const TemplateArgument *Args, unsigned ArgIdx = 0; while (ArgIdx < NumArgs) { const TemplateArgument &Arg = Args[ArgIdx]; - + // Unwrap argument packs. if (Args[ArgIdx].getKind() == TemplateArgument::Pack) { Args = Arg.pack_begin(); @@ -1475,15 +1475,15 @@ static bool hasPackExpansionBeforeEnd(const TemplateArgument *Args, ArgIdx = 0; continue; } - + ++ArgIdx; if (ArgIdx == NumArgs) return false; - + if (Arg.isPackExpansion()) return true; } - + return false; } @@ -1496,54 +1496,54 @@ DeduceTemplateArguments(Sema &S, llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced, bool NumberOfArgumentsMustMatch) { // 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 + // 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 // non-deduced context. if (hasPackExpansionBeforeEnd(Params, NumParams)) return Sema::TDK_Success; - + // C++0x [temp.deduct.type]p9: - // If P has a form that contains <T> or <i>, then each argument Pi of the - // respective template argument list P is compared with the corresponding + // If P has a form that contains <T> or <i>, then each argument Pi of the + // respective template argument list P is compared with the corresponding // argument Ai of the corresponding template argument list of A. unsigned ArgIdx = 0, ParamIdx = 0; - for (; hasTemplateArgumentForDeduction(Params, ParamIdx, NumParams); + for (; hasTemplateArgumentForDeduction(Params, ParamIdx, NumParams); ++ParamIdx) { if (!Params[ParamIdx].isPackExpansion()) { // The simple case: deduce template arguments by matching Pi and Ai. - + // Check whether we have enough arguments. if (!hasTemplateArgumentForDeduction(Args, ArgIdx, NumArgs)) return NumberOfArgumentsMustMatch? Sema::TDK_NonDeducedMismatch : 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; } - + // Perform deduction for this Pi/Ai pair. if (Sema::TemplateDeductionResult Result = DeduceTemplateArguments(S, TemplateParams, Params[ParamIdx], Args[ArgIdx], Info, Deduced)) - return Result; - + return Result; + // Move to the next argument. ++ArgIdx; continue; } - + // The parameter is a pack expansion. - + // C++0x [temp.deduct.type]p9: - // If Pi is a pack expansion, then the pattern of Pi is compared with - // each remaining argument in the template argument list of A. Each - // comparison deduces template arguments for subsequent positions in the + // If Pi is a pack expansion, then the pattern of Pi is compared with + // each remaining argument in the template argument list of A. Each + // comparison deduces template arguments for subsequent positions in the // template parameter packs expanded by Pi. TemplateArgument Pattern = Params[ParamIdx].getPackExpansionPattern(); - + // Compute the set of template parameter indices that correspond to // parameter packs expanded by the pack expansion. llvm::SmallVector<unsigned, 2> PackIndices; @ |