Skip to content

Commit 8a334af

Browse files
authored
[clang] Remove the deprecated flag -frelaxed-template-template-args. (#111894)
This flag has been deprecated since Clang 19, having been the default since then. It has remained because its negation was still useful to work around backwards compatibility breaking changes from P0522. However, in Clang 20 we have landed various changes which implemented P3310R2 and beyond, which solve almost all of the expected issues, the known remaining few being a bit obscure. So this change removes the flag completely and all of its implementation and support code. Hopefully any remaining users can just stop using the flag. If there are still important issues remaining, this removal will also shake the tree and help us know.
1 parent d3161de commit 8a334af

File tree

13 files changed

+113
-243
lines changed

13 files changed

+113
-243
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ C++17 Feature Support
7373
Resolutions to C++ Defect Reports
7474
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7575

76+
- The flag `-frelaxed-template-template-args`
77+
and its negation have been removed, having been deprecated since the previous
78+
two releases. The improvements to template template parameter matching implemented
79+
in the previous release, as described in P3310 and P3579, made this flag unnecessary.
80+
7681
C Language Changes
7782
------------------
7883

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,6 @@ def warn_drv_clang_unsupported : Warning<
445445
"the clang compiler does not support '%0'">;
446446
def warn_drv_deprecated_arg : Warning<
447447
"argument '%0' is deprecated%select{|, use '%2' instead}1">, InGroup<Deprecated>;
448-
def warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning<
449-
"argument '-fno-relaxed-template-template-args' is deprecated">,
450-
InGroup<DeprecatedNoRelaxedTemplateTemplateArgs>;
451448
def warn_drv_deprecated_arg_ofast : Warning<
452449
"argument '-Ofast' is deprecated; use '-O3 -ffast-math' for the same behavior,"
453450
" or '-O3' to enable only conforming optimizations">,

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def EnumConversion : DiagGroup<"enum-conversion",
102102
[EnumEnumConversion,
103103
EnumFloatConversion,
104104
EnumCompareConditional]>;
105-
def DeprecatedNoRelaxedTemplateTemplateArgs : DiagGroup<"deprecated-no-relaxed-template-template-args">;
106105
def DeprecatedOFast : DiagGroup<"deprecated-ofast">;
107106
def ObjCSignedCharBoolImplicitIntConversion :
108107
DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
@@ -230,7 +229,6 @@ def Deprecated : DiagGroup<"deprecated", [DeprecatedAnonEnumEnumConversion,
230229
DeprecatedLiteralOperator,
231230
DeprecatedPragma,
232231
DeprecatedRegister,
233-
DeprecatedNoRelaxedTemplateTemplateArgs,
234232
DeprecatedOFast,
235233
DeprecatedThisCapture,
236234
DeprecatedType,

clang/include/clang/Basic/LangOptions.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ LANGOPT(GNUAsm , 1, 1, "GNU-style inline assembly")
160160
LANGOPT(Coroutines , 1, 0, "C++20 coroutines")
161161
LANGOPT(CoroAlignedAllocation, 1, 0, "prefer Aligned Allocation according to P2014 Option 2")
162162
LANGOPT(DllExportInlines , 1, 1, "dllexported classes dllexport inline methods")
163-
LANGOPT(RelaxedTemplateTemplateArgs, 1, 1, "C++17 relaxed matching of template template arguments")
164163
LANGOPT(ExperimentalLibrary, 1, 0, "enable unstable and experimental library features")
165164
LANGOPT(RetainSubstTemplateTypeParmTypeAstNodes, 1, 0, "retain SubstTemplateTypeParmType nodes in the AST's representation of alias template specializations")
166165

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,11 +3557,6 @@ defm application_extension : BoolFOption<"application-extension",
35573557
PosFlag<SetTrue, [], [ClangOption, CC1Option],
35583558
"Restrict code to those available for App Extensions">,
35593559
NegFlag<SetFalse>>;
3560-
defm relaxed_template_template_args : BoolFOption<"relaxed-template-template-args",
3561-
LangOpts<"RelaxedTemplateTemplateArgs">, DefaultTrue,
3562-
PosFlag<SetTrue, [], [], "Enable">,
3563-
NegFlag<SetFalse, [], [CC1Option], "Disable">,
3564-
BothFlags<[], [ClangOption], " C++17 relaxed template template argument matching">>;
35653560
defm retain_subst_template_type_parm_type_ast_nodes : BoolFOption<"retain-subst-template-type-parm-type-ast-nodes",
35663561
LangOpts<"RetainSubstTemplateTypeParmTypeAstNodes">, DefaultFalse,
35673562
PosFlag<SetTrue, [], [CC1Option], "Enable">,

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11837,17 +11837,6 @@ class Sema final : public SemaBase {
1183711837
/// \endcode
1183811838
TPL_TemplateTemplateParmMatch,
1183911839

11840-
/// We are matching the template parameter lists of a template
11841-
/// template argument against the template parameter lists of a template
11842-
/// template parameter.
11843-
///
11844-
/// \code
11845-
/// template<template<int Value> class Metafun> struct X;
11846-
/// template<int Value> struct integer_c;
11847-
/// X<integer_c> xic;
11848-
/// \endcode
11849-
TPL_TemplateTemplateArgumentMatch,
11850-
1185111840
/// We are determining whether the template-parameters are equivalent
1185211841
/// according to C++ [temp.over.link]/6. This comparison does not consider
1185311842
/// constraints.

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7502,20 +7502,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
75027502
Args.addOptOutFlag(CmdArgs, options::OPT_fassume_unique_vtables,
75037503
options::OPT_fno_assume_unique_vtables);
75047504

7505-
// -frelaxed-template-template-args is deprecated.
7506-
if (Arg *A =
7507-
Args.getLastArg(options::OPT_frelaxed_template_template_args,
7508-
options::OPT_fno_relaxed_template_template_args)) {
7509-
if (A->getOption().matches(
7510-
options::OPT_fno_relaxed_template_template_args)) {
7511-
D.Diag(diag::warn_drv_deprecated_arg_no_relaxed_template_template_args);
7512-
CmdArgs.push_back("-fno-relaxed-template-template-args");
7513-
} else {
7514-
D.Diag(diag::warn_drv_deprecated_arg)
7515-
<< A->getAsString(Args) << /*hasReplacement=*/false;
7516-
}
7517-
}
7518-
75197505
// -fsized-deallocation is on by default in C++14 onwards and otherwise off
75207506
// by default.
75217507
Args.addLastArg(CmdArgs, options::OPT_fsized_deallocation,

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,8 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
729729
}
730730
if (LangOpts.AlignedAllocation && !LangOpts.AlignedAllocationUnavailable)
731731
Builder.defineMacro("__cpp_aligned_new", "201606L");
732-
if (LangOpts.RelaxedTemplateTemplateArgs)
733-
Builder.defineMacro("__cpp_template_template_args", "201611L");
732+
733+
Builder.defineMacro("__cpp_template_template_args", "201611L");
734734

735735
// C++20 features.
736736
if (LangOpts.CPlusPlus20) {

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 34 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -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

clang/test/Driver/frelaxed-template-template-args.cpp

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)