Skip to content

Commit 2d7fba5

Browse files
committed
[clang] deprecate frelaxed-template-template-args, make it on by default
A resolution to the ambiguity issues created by P0522, which is a DR solving CWG 150, did not come as expected, so we are just going to accept the change, and watch how users digest it. For now we deprecate the flag with a warning, and make it on by default. We don't remove the flag completely in order to give users a chance to work around any problems by disabling it. Signed-off-by: Matheus Izvekov <[email protected]> Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D109496
1 parent de7494a commit 2d7fba5

17 files changed

+70
-58
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def warn_drv_diagnostics_hotness_requires_pgo : Warning<
355355
def warn_drv_clang_unsupported : Warning<
356356
"the clang compiler does not support '%0'">;
357357
def warn_drv_deprecated_arg : Warning<
358-
"argument '%0' is deprecated, use '%1' instead">, InGroup<Deprecated>;
358+
"argument '%0' is deprecated%select{|, use '%2' instead}1">, InGroup<Deprecated>;
359359
def warn_drv_assuming_mfloat_abi_is : Warning<
360360
"unknown platform, assuming -mfloat-abi=%0">;
361361
def warn_ignoring_ftabstop_value : Warning<

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ LANGOPT(NoMathBuiltin , 1, 0, "disable math builtin functions")
149149
LANGOPT(GNUAsm , 1, 1, "GNU-style inline assembly")
150150
LANGOPT(Coroutines , 1, 0, "C++20 coroutines")
151151
LANGOPT(DllExportInlines , 1, 1, "dllexported classes dllexport inline methods")
152-
LANGOPT(RelaxedTemplateTemplateArgs, 1, 0, "C++17 relaxed matching of template template arguments")
152+
LANGOPT(RelaxedTemplateTemplateArgs, 1, 1, "C++17 relaxed matching of template template arguments")
153153

154154
LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for all language standard modes")
155155

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,9 +2335,9 @@ defm application_extension : BoolFOption<"application-extension",
23352335
PosFlag<SetTrue, [CC1Option], "Restrict code to those available for App Extensions">,
23362336
NegFlag<SetFalse>>;
23372337
defm relaxed_template_template_args : BoolFOption<"relaxed-template-template-args",
2338-
LangOpts<"RelaxedTemplateTemplateArgs">, DefaultFalse,
2339-
PosFlag<SetTrue, [CC1Option], "Enable C++17 relaxed template template argument matching">,
2340-
NegFlag<SetFalse>>;
2338+
LangOpts<"RelaxedTemplateTemplateArgs">, DefaultTrue,
2339+
PosFlag<SetTrue>,
2340+
NegFlag<SetFalse, [CC1Option], "Disable C++17 relaxed template template argument matching">>;
23412341
defm sized_deallocation : BoolFOption<"sized-deallocation",
23422342
LangOpts<"SizedDeallocation">, DefaultFalse,
23432343
PosFlag<SetTrue, [CC1Option], "Enable C++14 sized global deallocation functions">,

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,8 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
683683
Arg->claim();
684684
if (LegacySanitizeCoverage != 0) {
685685
D.Diag(diag::warn_drv_deprecated_arg)
686-
<< Arg->getAsString(Args) << "-fsanitize-coverage=trace-pc-guard";
686+
<< Arg->getAsString(Args) << true
687+
<< "-fsanitize-coverage=trace-pc-guard";
687688
}
688689
continue;
689690
}
@@ -718,11 +719,11 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
718719
// enabled.
719720
if (CoverageFeatures & CoverageTraceBB)
720721
D.Diag(clang::diag::warn_drv_deprecated_arg)
721-
<< "-fsanitize-coverage=trace-bb"
722+
<< "-fsanitize-coverage=trace-bb" << true
722723
<< "-fsanitize-coverage=trace-pc-guard";
723724
if (CoverageFeatures & Coverage8bitCounters)
724725
D.Diag(clang::diag::warn_drv_deprecated_arg)
725-
<< "-fsanitize-coverage=8bit-counters"
726+
<< "-fsanitize-coverage=8bit-counters" << true
726727
<< "-fsanitize-coverage=trace-pc-guard";
727728

728729
int InsertionPointTypes = CoverageFunc | CoverageBB | CoverageEdge;
@@ -732,7 +733,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
732733
if ((CoverageFeatures & InsertionPointTypes) &&
733734
!(CoverageFeatures & InstrumentationTypes)) {
734735
D.Diag(clang::diag::warn_drv_deprecated_arg)
735-
<< "-fsanitize-coverage=[func|bb|edge]"
736+
<< "-fsanitize-coverage=[func|bb|edge]" << true
736737
<< "-fsanitize-coverage=[func|bb|edge],[trace-pc-guard|trace-pc]";
737738
}
738739

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6391,12 +6391,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
63916391
options::OPT_fno_assume_sane_operator_new))
63926392
CmdArgs.push_back("-fno-assume-sane-operator-new");
63936393

6394-
// -frelaxed-template-template-args is off by default, as it is a severe
6395-
// breaking change until a corresponding change to template partial ordering
6396-
// is provided.
6397-
if (Args.hasFlag(options::OPT_frelaxed_template_template_args,
6398-
options::OPT_fno_relaxed_template_template_args, false))
6399-
CmdArgs.push_back("-frelaxed-template-template-args");
6394+
// -frelaxed-template-template-args is deprecated and on by default.
6395+
if (Arg *A =
6396+
Args.getLastArg(options::OPT_frelaxed_template_template_args,
6397+
options::OPT_fno_relaxed_template_template_args)) {
6398+
D.Diag(diag::warn_drv_deprecated_arg) << A->getAsString(Args) << false;
6399+
if (A->getOption().matches(options::OPT_fno_relaxed_template_template_args))
6400+
CmdArgs.push_back("-fno-relaxed-template-template-args");
6401+
}
64006402

64016403
// -fsized-deallocation is off by default, as it is an ABI-breaking change for
64026404
// most platforms.

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,12 +1890,12 @@ void tools::checkAMDGPUCodeObjectVersion(const Driver &D,
18901890

18911891
// Emit warnings for legacy options even if they are overridden.
18921892
if (Args.hasArg(options::OPT_mno_code_object_v3_legacy))
1893-
D.Diag(diag::warn_drv_deprecated_arg) << "-mno-code-object-v3"
1894-
<< "-mcode-object-version=2";
1893+
D.Diag(diag::warn_drv_deprecated_arg)
1894+
<< "-mno-code-object-v3" << true << "-mcode-object-version=2";
18951895

18961896
if (Args.hasArg(options::OPT_mcode_object_v3_legacy))
1897-
D.Diag(diag::warn_drv_deprecated_arg) << "-mcode-object-v3"
1898-
<< "-mcode-object-version=3";
1897+
D.Diag(diag::warn_drv_deprecated_arg)
1898+
<< "-mcode-object-v3" << true << "-mcode-object-version=3";
18991899

19001900
if (auto *CodeObjArg = getAMDGPUCodeObjectArgument(D, Args)) {
19011901
if (CodeObjArg->getOption().getID() ==

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7407,9 +7407,7 @@ bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
74077407
// C++1z [temp.arg.template]p3: (DR 150)
74087408
// A template-argument matches a template template-parameter P when P
74097409
// is at least as specialized as the template-argument A.
7410-
// FIXME: We should enable RelaxedTemplateTemplateArgs by default as it is a
7411-
// defect report resolution from C++17 and shouldn't be introduced by
7412-
// concepts.
7410+
// FIXME: RelaxedTemplateTemplateArgs is deprecated, should be always on.
74137411
if (getLangOpts().RelaxedTemplateTemplateArgs) {
74147412
// Quick check for the common case:
74157413
// If P contains a parameter pack, then A [...] matches P if each of A's

clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -std=c++2a -frelaxed-template-template-args -verify %s
1+
// RUN: %clang_cc1 -std=c++2a -verify %s
22

33
template<typename T> concept C = T::f();
44
// expected-note@-1{{similar constraint}}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang -fsyntax-only -frelaxed-template-template-args %s 2>&1 | FileCheck --check-prefix=CHECK-ON %s
2+
// RUN: %clang -fsyntax-only -fno-relaxed-template-template-args %s 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
3+
4+
// CHECK-ON: warning: argument '-frelaxed-template-template-args' is deprecated [-Wdeprecated]
5+
// CHECK-OFF: warning: argument '-fno-relaxed-template-template-args' is deprecated [-Wdeprecated]

clang/test/Lexer/cxx-features.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// RUN: %clang_cc1 -std=c++20 -fcxx-exceptions -fsized-deallocation -verify %s
66
// RUN: %clang_cc1 -std=c++2b -fcxx-exceptions -fsized-deallocation -verify %s
77
//
8-
// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -frelaxed-template-template-args -DRELAXED_TEMPLATE_TEMPLATE_ARGS=1 -verify %s
8+
// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -fno-relaxed-template-template-args -DNO_RELAXED_TEMPLATE_TEMPLATE_ARGS=1 -verify %s
99
// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -DCONCEPTS_TS=1 -verify %s
1010
// RUN: %clang_cc1 -std=c++14 -fno-rtti -fno-threadsafe-statics -verify %s -DNO_EXCEPTIONS -DNO_RTTI -DNO_THREADSAFE_STATICS -fsized-deallocation
1111
// RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -DNO_EXCEPTIONS -DCOROUTINES -verify -fsized-deallocation %s
@@ -195,9 +195,9 @@
195195
#error "wrong value for __cpp_nontype_template_args"
196196
#endif
197197

198-
#if defined(RELAXED_TEMPLATE_TEMPLATE_ARGS) \
199-
? check(template_template_args, 0, 0, 0, 201611, 201611, 201611) \
200-
: check(template_template_args, 0, 0, 0, 0, 0, 0)
198+
#if defined(NO_RELAXED_TEMPLATE_TEMPLATE_ARGS) \
199+
? check(template_template_args, 0, 0, 0, 0, 0, 0) \
200+
: check(template_template_args, 201611, 201611, 201611, 201611, 201611, 201611)
201201
#error "wrong value for __cpp_template_template_args"
202202
#endif
203203

clang/test/SemaTemplate/deduction.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ struct Replace<const T, Arg1, Arg2> {
6060
// Replacement of templates
6161
template<template<typename> class TT, typename T1, typename Arg1, typename Arg2>
6262
struct Replace<TT<T1>, Arg1, Arg2> {
63+
// expected-note@-1 2 {{partial specialization matches}}
6364
typedef TT<typename Replace<T1, Arg1, Arg2>::type> type;
6465
};
6566

6667
template<template<typename, typename> class TT, typename T1, typename T2,
6768
typename Arg1, typename Arg2>
6869
struct Replace<TT<T1, T2>, Arg1, Arg2> {
70+
// expected-note@-1 2 {{partial specialization matches}}
6971
typedef TT<typename Replace<T1, Arg1, Arg2>::type,
7072
typename Replace<T2, Arg1, Arg2>::type> type;
7173
};
@@ -79,8 +81,19 @@ struct Replace<TT<T1, _2>, Arg1, Arg2> {
7981

8082
int array0[is_same<Replace<_1, int, float>::type, int>::value? 1 : -1];
8183
int array1[is_same<Replace<const _1, int, float>::type, const int>::value? 1 : -1];
84+
8285
int array2[is_same<Replace<vector<_1>, int, float>::type, vector<int> >::value? 1 : -1];
86+
// expected-error@-1 {{ambiguous partial specializations of 'Replace<vector<_1>, int, float>'}}
87+
// FIXME: Some bad error recovery from the parser here:
88+
// expected-error@-3 {{expected '(' for function-style cast or type construction}}
89+
// expected-error@-4 {{no member named 'value' in the global namespace}}
90+
8391
int array3[is_same<Replace<vector<const _1>, int, float>::type, vector<const int> >::value? 1 : -1];
92+
// expected-error@-1 {{ambiguous partial specializations of 'Replace<vector<const _1>, int, float>'}}
93+
// FIXME: Some bad error recovery from the parser here:
94+
// expected-error@-3 {{expected '(' for function-style cast or type construction}}
95+
// expected-error@-4 {{no member named 'value' in the global namespace}}
96+
8497
int array4[is_same<Replace<vector<int, _2>, double, float>::type, vector<int, float> >::value? 1 : -1];
8598

8699
// PR5911

clang/test/SemaTemplate/default-arguments.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,14 @@ template<typename T, template<typename> class X = T::template apply>
112112
int array4[is_same<X4<add_pointer>,
113113
X4<add_pointer, add_pointer::apply> >::value? 1 : -1];
114114

115-
template<int> struct X5 {}; // expected-note{{has a different type 'int'}}
115+
template<int> struct X5 {};
116116
template<long> struct X5b {};
117117
template<typename T,
118-
template<T> class B = X5> // expected-error{{template template argument has different}} \
119-
// expected-note{{previous non-type template parameter}}
118+
template<T> class B = X5>
120119
struct X6 {};
121120

122121
X6<int> x6a;
123-
X6<long> x6b; // expected-note{{while checking a default template argument}}
122+
X6<long> x6b;
124123
X6<long, X5b> x6c;
125124

126125

clang/test/SemaTemplate/instantiate-template-template-parm.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,29 @@ apply<add_reference, int>::type ir = i;
2020
apply<add_reference, float>::type fr = i; // expected-error{{non-const lvalue reference to type 'float' cannot bind to a value of unrelated type 'int'}}
2121

2222
// Template template parameters
23-
template<int> struct B; // expected-note{{has a different type 'int'}}
23+
template<int> struct B;
2424

2525
template<typename T,
26-
template<T Value> class X> // expected-error{{cannot have type 'float'}} \
27-
// expected-note{{with type 'long'}}
26+
template<T Value> class X> // expected-error{{cannot have type 'float'}}
2827
struct X0 { };
2928

3029
X0<int, B> x0b1;
3130
X0<float, B> x0b2; // expected-note{{while substituting}}
32-
X0<long, B> x0b3; // expected-error{{template template argument has different template parameters}}
31+
X0<long, B> x0b3;
3332

34-
template<template<int V> class TT> // expected-note{{parameter with type 'int'}}
33+
template<template<int V> class TT>
3534
struct X1 { };
3635

3736
template<typename T, template<T V> class TT>
3837
struct X2 {
39-
X1<TT> x1; // expected-error{{has different template parameters}}
38+
X1<TT> x1;
4039
};
4140

4241
template<int V> struct X3i { };
43-
template<long V> struct X3l { }; // expected-note{{different type 'long'}}
42+
template<long V> struct X3l { };
4443

4544
X2<int, X3i> x2okay;
46-
X2<long, X3l> x2bad; // expected-note{{instantiation}}
45+
X2<long, X3l> x2bad;
4746

4847
template <typename T, template <T, T> class TT, class R = TT<1, 2> >
4948
struct Comp {

clang/test/SemaTemplate/nested-template.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,16 @@ template struct X1<int>::B<bool>;
112112
// Template template parameters
113113
template<typename T>
114114
struct X2 {
115-
template<template<class U, T Value> class> // expected-error{{cannot have type 'float'}} \
116-
// expected-note{{previous non-type template}}
115+
template<template<class U, T Value> class> // expected-error{{cannot have type 'float'}}
117116
struct Inner { };
118117
};
119118

120-
template<typename T,
121-
int Value> // expected-note{{template non-type parameter}}
119+
template<typename T, int Value>
122120
struct X2_arg;
123121

124122
X2<int>::Inner<X2_arg> x2i1;
125123
X2<float> x2a; // expected-note{{instantiation}}
126-
X2<long>::Inner<X2_arg> x2i3; // expected-error{{template template argument has different}}
124+
X2<long>::Inner<X2_arg> x2i3;
127125

128126
namespace PR10896 {
129127
template<typename TN>

clang/test/SemaTemplate/temp_arg_template.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ template<template<typename T> class X> struct A; // expected-note 2{{previous te
66

77
template<template<typename T, int I> class X> struct B; // expected-note{{previous template template parameter is here}}
88

9-
template<template<int I> class X> struct C; // expected-note 2{{previous non-type template parameter with type 'int' is here}}
9+
template<template<int I> class X> struct C; // expected-note {{previous non-type template parameter with type 'int' is here}}
1010

1111
template<class> struct X; // expected-note{{too few template parameters in template template argument}}
1212
template<int N> struct Y; // expected-note{{template parameter has a different kind in template argument}}
13-
template<long N> struct Ylong; // expected-note{{template non-type parameter has a different type 'long' in template argument}}
13+
template<long N> struct Ylong;
1414
template<const int &N> struct Yref; // expected-note{{template non-type parameter has a different type 'const int &' in template argument}}
1515

1616
namespace N {
@@ -27,7 +27,7 @@ A<Y> *a4; // expected-error{{template template argument has different template p
2727
A<TooMany> *a5; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
2828
B<X> *a6; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
2929
C<Y> *a7;
30-
C<Ylong> *a8; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
30+
C<Ylong> *a8;
3131
C<Yref> *a9; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
3232

3333
template<typename T> void f(int);

clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -frelaxed-template-template-args %s
1+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s
22

33
// expected-note@temp_arg_template_cxx1z.cpp:* 1+{{}}
44

clang/www/cxx_status.html

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ <h2 id="cxx17">C++17 implementation status</h2>
596596
<p>You can use Clang in C++17 mode with the <code>-std=c++17</code> option
597597
(use <code>-std=c++1z</code> in Clang 4 and earlier).</p>
598598

599-
<details open>
599+
<details>
600600
<summary>List of features and minimum Clang version with support</summary>
601601

602602
<table width="689" border="1" cellspacing="0">
@@ -813,8 +813,8 @@ <h2 id="cxx17">C++17 implementation status</h2>
813813
<!-- Issaquah 2016 papers -->
814814
<tr>
815815
<td>Matching template template parameters to compatible arguments</td>
816-
<td><a href="https://wg21.link/p0522r0">P0522R0</a></td>
817-
<td class="partial" align="center">Partial <a href="#p0522">(10)</a></td>
816+
<td><a href="https://wg21.link/p0522r0">P0522R0</a> (<a href="#dr">DR</a>)</td>
817+
<td class="full" align="center">Clang 4 <a href="#p0522">(10)</a></td>
818818
</tr>
819819
<tr>
820820
<td>Removing deprecated dynamic exception specifications</td>
@@ -842,13 +842,10 @@ <h2 id="cxx17">C++17 implementation status</h2>
842842
reverse construction order in that ABI.
843843
This is not fully supported during constant expression evaluation until Clang 12.
844844
</span><br>
845-
<span id="p0522">(10): Despite being the resolution to a Defect Report, this
846-
feature is disabled by default in all language versions, and can be enabled
847-
explicitly with the flag <tt>-frelaxed-template-template-args</tt> in Clang 4
848-
onwards.
849-
The change to the standard lacks a corresponding change for template partial
850-
ordering, resulting in ambiguity errors for reasonable and previously-valid
851-
code. This issue is expected to be rectified soon.
845+
<span id="p0522">(10): Prior to Clang 14, this feature is not enabled by
846+
default, but can be enabled with <tt>-frelaxed-template-template-args</tt>.
847+
Starting from Clang 14, the flag is deprecated and will be removed in a future
848+
version.
852849
</span>
853850
</p>
854851
</details>

0 commit comments

Comments
 (0)