diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 3e4e288e143a3..d7f0f1184a7e6 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -8457,24 +8457,31 @@ class Sema final { /// template struct integer_c; /// X xic; /// \endcode - TPL_TemplateTemplateArgumentMatch + TPL_TemplateTemplateArgumentMatch, + + /// We are determining whether the template-parameters are equivalent + /// according to C++ [temp.over.link]/6. This comparison does not consider + /// constraints. + /// + /// \code + /// template void f(T); + /// template void f(T); + /// \endcode + TPL_TemplateParamsEquivalent, }; bool TemplateParameterListsAreEqual( const NamedDecl *NewInstFrom, TemplateParameterList *New, const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain, TemplateParameterListEqualKind Kind, - SourceLocation TemplateArgLoc = SourceLocation(), - bool PartialOrdering = false); + SourceLocation TemplateArgLoc = SourceLocation()); bool TemplateParameterListsAreEqual( TemplateParameterList *New, TemplateParameterList *Old, bool Complain, TemplateParameterListEqualKind Kind, - SourceLocation TemplateArgLoc = SourceLocation(), - bool PartialOrdering = false) { + SourceLocation TemplateArgLoc = SourceLocation()) { return TemplateParameterListsAreEqual(nullptr, New, nullptr, Old, Complain, - Kind, TemplateArgLoc, - PartialOrdering); + Kind, TemplateArgLoc); } bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index f1de491f1cd33..4a667d046f149 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -7967,8 +7967,7 @@ Sema::BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, static bool MatchTemplateParameterKind( Sema &S, NamedDecl *New, const NamedDecl *NewInstFrom, NamedDecl *Old, const NamedDecl *OldInstFrom, bool Complain, - Sema::TemplateParameterListEqualKind Kind, SourceLocation TemplateArgLoc, - bool PartialOrdering) { + Sema::TemplateParameterListEqualKind Kind, SourceLocation TemplateArgLoc) { // Check the actual kind (type, non-type, template). if (Old->getKind() != New->getKind()) { if (Complain) { @@ -8056,11 +8055,12 @@ static bool MatchTemplateParameterKind( (Kind == Sema::TPL_TemplateMatch ? Sema::TPL_TemplateTemplateParmMatch : Kind), - TemplateArgLoc, PartialOrdering)) + TemplateArgLoc)) return false; } - if (!PartialOrdering && Kind != Sema::TPL_TemplateTemplateArgumentMatch && + if (Kind != Sema::TPL_TemplateParamsEquivalent && + Kind != Sema::TPL_TemplateTemplateArgumentMatch && !isa(Old)) { const Expr *NewC = nullptr, *OldC = nullptr; @@ -8153,8 +8153,7 @@ void DiagnoseTemplateParameterListArityMismatch(Sema &S, bool Sema::TemplateParameterListsAreEqual( const NamedDecl *NewInstFrom, TemplateParameterList *New, const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain, - TemplateParameterListEqualKind Kind, SourceLocation TemplateArgLoc, - bool PartialOrdering) { + TemplateParameterListEqualKind Kind, SourceLocation TemplateArgLoc) { if (Old->size() != New->size() && Kind != TPL_TemplateTemplateArgumentMatch) { if (Complain) DiagnoseTemplateParameterListArityMismatch(*this, New, Old, Kind, @@ -8186,7 +8185,7 @@ bool Sema::TemplateParameterListsAreEqual( if (!MatchTemplateParameterKind(*this, *NewParm, NewInstFrom, *OldParm, OldInstFrom, Complain, Kind, - TemplateArgLoc, PartialOrdering)) + TemplateArgLoc)) return false; ++NewParm; @@ -8203,7 +8202,7 @@ bool Sema::TemplateParameterListsAreEqual( for (; NewParm != NewParmEnd; ++NewParm) { if (!MatchTemplateParameterKind(*this, *NewParm, NewInstFrom, *OldParm, OldInstFrom, Complain, Kind, - TemplateArgLoc, PartialOrdering)) + TemplateArgLoc)) return false; } } @@ -8217,7 +8216,8 @@ bool Sema::TemplateParameterListsAreEqual( return false; } - if (!PartialOrdering && Kind != TPL_TemplateTemplateArgumentMatch) { + if (Kind != TPL_TemplateTemplateArgumentMatch && + Kind != TPL_TemplateParamsEquivalent) { const Expr *NewRC = New->getRequiresClause(); const Expr *OldRC = Old->getRequiresClause(); diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 1fe2d3fac6859..611ebc9859388 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -5279,8 +5279,8 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate( // function parameters that positionally correspond between the two // templates are not of the same type, neither template is more specialized // than the other. - if (!TemplateParameterListsAreEqual( - TPL1, TPL2, false, Sema::TPL_TemplateMatch, SourceLocation(), true)) + if (!TemplateParameterListsAreEqual(TPL1, TPL2, false, + Sema::TPL_TemplateParamsEquivalent)) return nullptr; for (unsigned i = 0; i < NumParams1; ++i) @@ -5637,8 +5637,8 @@ getMoreSpecialized(Sema &S, QualType T1, QualType T2, TemplateLikeDecl *P1, // function parameters that positionally correspond between the two // templates are not of the same type, neither template is more specialized // than the other. - if (!S.TemplateParameterListsAreEqual( - TPL1, TPL2, false, Sema::TPL_TemplateMatch, SourceLocation(), true)) + if (!S.TemplateParameterListsAreEqual(TPL1, TPL2, false, + Sema::TPL_TemplateParamsEquivalent)) return nullptr; if (!TemplateArgumentListAreEqual(S.getASTContext())(P1, P2))