@@ -7399,11 +7399,6 @@ bool Sema::CheckTemplateTemplateArgument(
73997399 << Template;
74007400 }
74017401
7402- if (!getLangOpts ().RelaxedTemplateTemplateArgs )
7403- return !TemplateParameterListsAreEqual (
7404- Template->getTemplateParameters (), Params, /* Complain=*/ true ,
7405- TPL_TemplateTemplateArgumentMatch, Arg.getLocation ());
7406-
74077402 // C++1z [temp.arg.template]p3: (DR 150)
74087403 // A template-argument matches a template template-parameter P when P
74097404 // is at least as specialized as the template-argument A.
@@ -7775,9 +7770,7 @@ static bool MatchTemplateParameterKind(
77757770 // However, if we are matching a template template argument to a
77767771 // template template parameter, the template template parameter can have
77777772 // a parameter pack where the template template argument does not.
7778- if (Old->isTemplateParameterPack () != New->isTemplateParameterPack () &&
7779- !(Kind == Sema::TPL_TemplateTemplateArgumentMatch &&
7780- Old->isTemplateParameterPack ())) {
7773+ if (Old->isTemplateParameterPack () != New->isTemplateParameterPack ()) {
77817774 if (Complain) {
77827775 unsigned NextDiag = diag::err_template_parameter_pack_non_pack;
77837776 if (TemplateArgLoc.isValid ()) {
@@ -7803,37 +7796,28 @@ static bool MatchTemplateParameterKind(
78037796 = dyn_cast<NonTypeTemplateParmDecl>(Old)) {
78047797 NonTypeTemplateParmDecl *NewNTTP = cast<NonTypeTemplateParmDecl>(New);
78057798
7806- // If we are matching a template template argument to a template
7807- // template parameter and one of the non-type template parameter types
7808- // is dependent, then we must wait until template instantiation time
7809- // to actually compare the arguments.
7810- if (Kind != Sema::TPL_TemplateTemplateArgumentMatch ||
7811- (!OldNTTP->getType ()->isDependentType () &&
7812- !NewNTTP->getType ()->isDependentType ())) {
7813- // C++20 [temp.over.link]p6:
7814- // Two [non-type] template-parameters are equivalent [if] they have
7815- // equivalent types ignoring the use of type-constraints for
7816- // placeholder types
7817- QualType OldType = S.Context .getUnconstrainedType (OldNTTP->getType ());
7818- QualType NewType = S.Context .getUnconstrainedType (NewNTTP->getType ());
7819- if (!S.Context .hasSameType (OldType, NewType)) {
7820- if (Complain) {
7821- unsigned NextDiag = diag::err_template_nontype_parm_different_type;
7822- if (TemplateArgLoc.isValid ()) {
7823- S.Diag (TemplateArgLoc,
7824- diag::err_template_arg_template_params_mismatch);
7825- NextDiag = diag::note_template_nontype_parm_different_type;
7826- }
7827- S.Diag (NewNTTP->getLocation (), NextDiag)
7828- << NewNTTP->getType ()
7829- << (Kind != Sema::TPL_TemplateMatch);
7830- S.Diag (OldNTTP->getLocation (),
7831- diag::note_template_nontype_parm_prev_declaration)
7832- << OldNTTP->getType ();
7799+ // C++20 [temp.over.link]p6:
7800+ // Two [non-type] template-parameters are equivalent [if] they have
7801+ // equivalent types ignoring the use of type-constraints for
7802+ // placeholder types
7803+ QualType OldType = S.Context .getUnconstrainedType (OldNTTP->getType ());
7804+ QualType NewType = S.Context .getUnconstrainedType (NewNTTP->getType ());
7805+ if (!S.Context .hasSameType (OldType, NewType)) {
7806+ if (Complain) {
7807+ unsigned NextDiag = diag::err_template_nontype_parm_different_type;
7808+ if (TemplateArgLoc.isValid ()) {
7809+ S.Diag (TemplateArgLoc,
7810+ diag::err_template_arg_template_params_mismatch);
7811+ NextDiag = diag::note_template_nontype_parm_different_type;
78337812 }
7834-
7835- return false ;
7813+ S.Diag (NewNTTP->getLocation (), NextDiag)
7814+ << NewNTTP->getType () << (Kind != Sema::TPL_TemplateMatch);
7815+ S.Diag (OldNTTP->getLocation (),
7816+ diag::note_template_nontype_parm_prev_declaration)
7817+ << OldNTTP->getType ();
78367818 }
7819+
7820+ return false ;
78377821 }
78387822 }
78397823 // For template template parameters, check the template parameter types.
@@ -7853,7 +7837,6 @@ static bool MatchTemplateParameterKind(
78537837 }
78547838
78557839 if (Kind != Sema::TPL_TemplateParamsEquivalent &&
7856- Kind != Sema::TPL_TemplateTemplateArgumentMatch &&
78577840 !isa<TemplateTemplateParmDecl>(Old)) {
78587841 const Expr *NewC = nullptr , *OldC = nullptr ;
78597842
@@ -7924,7 +7907,7 @@ bool Sema::TemplateParameterListsAreEqual(
79247907 const TemplateCompareNewDeclInfo &NewInstFrom, TemplateParameterList *New,
79257908 const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain,
79267909 TemplateParameterListEqualKind Kind, SourceLocation TemplateArgLoc) {
7927- if (Old->size () != New->size () && Kind != TPL_TemplateTemplateArgumentMatch ) {
7910+ if (Old->size () != New->size ()) {
79287911 if (Complain)
79297912 DiagnoseTemplateParameterListArityMismatch (*this , New, Old, Kind,
79307913 TemplateArgLoc);
@@ -7941,40 +7924,18 @@ bool Sema::TemplateParameterListsAreEqual(
79417924 TemplateParameterList::iterator NewParm = New->begin ();
79427925 TemplateParameterList::iterator NewParmEnd = New->end ();
79437926 for (TemplateParameterList::iterator OldParm = Old->begin (),
7944- OldParmEnd = Old->end ();
7945- OldParm != OldParmEnd; ++OldParm) {
7946- if (Kind != TPL_TemplateTemplateArgumentMatch ||
7947- !(*OldParm)->isTemplateParameterPack ()) {
7948- if (NewParm == NewParmEnd) {
7949- if (Complain)
7950- DiagnoseTemplateParameterListArityMismatch (*this , New, Old, Kind,
7951- TemplateArgLoc);
7952-
7953- return false ;
7954- }
7955-
7956- if (!MatchTemplateParameterKind (*this , *NewParm, NewInstFrom, *OldParm,
7957- OldInstFrom, Complain, Kind,
7958- TemplateArgLoc))
7959- return false ;
7960-
7961- ++NewParm;
7962- continue ;
7963- }
7964-
7965- // C++0x [temp.arg.template]p3:
7966- // [...] When P's template- parameter-list contains a template parameter
7967- // pack (14.5.3), the template parameter pack will match zero or more
7968- // template parameters or template parameter packs in the
7969- // template-parameter-list of A with the same type and form as the
7970- // template parameter pack in P (ignoring whether those template
7971- // parameters are template parameter packs).
7972- for (; NewParm != NewParmEnd; ++NewParm) {
7973- if (!MatchTemplateParameterKind (*this , *NewParm, NewInstFrom, *OldParm,
7974- OldInstFrom, Complain, Kind,
7975- TemplateArgLoc))
7976- return false ;
7927+ OldParmEnd = Old->end ();
7928+ OldParm != OldParmEnd; ++OldParm, ++NewParm) {
7929+ if (NewParm == NewParmEnd) {
7930+ if (Complain)
7931+ DiagnoseTemplateParameterListArityMismatch (*this , New, Old, Kind,
7932+ TemplateArgLoc);
7933+ return false ;
79777934 }
7935+ if (!MatchTemplateParameterKind (*this , *NewParm, NewInstFrom, *OldParm,
7936+ OldInstFrom, Complain, Kind,
7937+ TemplateArgLoc))
7938+ return false ;
79787939 }
79797940
79807941 // Make sure we exhausted all of the arguments.
@@ -7986,8 +7947,7 @@ bool Sema::TemplateParameterListsAreEqual(
79867947 return false ;
79877948 }
79887949
7989- if (Kind != TPL_TemplateTemplateArgumentMatch &&
7990- Kind != TPL_TemplateParamsEquivalent) {
7950+ if (Kind != TPL_TemplateParamsEquivalent) {
79917951 const Expr *NewRC = New->getRequiresClause ();
79927952 const Expr *OldRC = Old->getRequiresClause ();
79937953
0 commit comments