Author: Yaxun (Sam) Liu Date: 2021-11-02T17:02:19-04:00 New Revision: 60a085beb04b055cf44c379c56cb247cb3587658
URL: https://github.com/llvm/llvm-project/commit/60a085beb04b055cf44c379c56cb247cb3587658 DIFF: https://github.com/llvm/llvm-project/commit/60a085beb04b055cf44c379c56cb247cb3587658.diff LOG: Revert "[clang] deprecate frelaxed-template-template-args, make it on by default" This reverts commit 2d7fba5f95f0614f6f2c4a4ed966b307d617898b. The patch was reverted because it caused regression with rocThrust due to ambiguity of template specialization. For details please see https://reviews.llvm.org/D109496 Added: Modified: clang/include/clang/Basic/DiagnosticDriverKinds.td clang/include/clang/Basic/LangOptions.def clang/include/clang/Driver/Options.td clang/lib/Driver/SanitizerArgs.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Sema/SemaTemplate.cpp clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp clang/test/Lexer/cxx-features.cpp clang/test/SemaTemplate/deduction.cpp clang/test/SemaTemplate/default-arguments.cpp clang/test/SemaTemplate/instantiate-template-template-parm.cpp clang/test/SemaTemplate/nested-template.cpp clang/test/SemaTemplate/temp_arg_template.cpp clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp clang/www/cxx_status.html Removed: clang/test/Driver/frelaxed-template-template-args.cpp ################################################################################ diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index b823ade0eafb5..fa464952189ba 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -355,7 +355,7 @@ def warn_drv_diagnostics_hotness_requires_pgo : Warning< def warn_drv_clang_unsupported : Warning< "the clang compiler does not support '%0'">; def warn_drv_deprecated_arg : Warning< - "argument '%0' is deprecated%select{|, use '%2' instead}1">, InGroup<Deprecated>; + "argument '%0' is deprecated, use '%1' instead">, InGroup<Deprecated>; def warn_drv_assuming_mfloat_abi_is : Warning< "unknown platform, assuming -mfloat-abi=%0">; def warn_ignoring_ftabstop_value : Warning< diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 565ecd94f977c..4651f4fff6aa0 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -149,7 +149,7 @@ LANGOPT(NoMathBuiltin , 1, 0, "disable math builtin functions") LANGOPT(GNUAsm , 1, 1, "GNU-style inline assembly") LANGOPT(Coroutines , 1, 0, "C++20 coroutines") LANGOPT(DllExportInlines , 1, 1, "dllexported classes dllexport inline methods") -LANGOPT(RelaxedTemplateTemplateArgs, 1, 1, "C++17 relaxed matching of template template arguments") +LANGOPT(RelaxedTemplateTemplateArgs, 1, 0, "C++17 relaxed matching of template template arguments") LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for all language standard modes") diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 0d3c053e89ae4..b4a2411fa5c5c 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2335,9 +2335,9 @@ defm application_extension : BoolFOption<"application-extension", PosFlag<SetTrue, [CC1Option], "Restrict code to those available for App Extensions">, NegFlag<SetFalse>>; defm relaxed_template_template_args : BoolFOption<"relaxed-template-template-args", - LangOpts<"RelaxedTemplateTemplateArgs">, DefaultTrue, - PosFlag<SetTrue>, - NegFlag<SetFalse, [CC1Option], "Disable C++17 relaxed template template argument matching">>; + LangOpts<"RelaxedTemplateTemplateArgs">, DefaultFalse, + PosFlag<SetTrue, [CC1Option], "Enable C++17 relaxed template template argument matching">, + NegFlag<SetFalse>>; defm sized_deallocation : BoolFOption<"sized-deallocation", LangOpts<"SizedDeallocation">, DefaultFalse, PosFlag<SetTrue, [CC1Option], "Enable C++14 sized global deallocation functions">, diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp index 6f426c6cad69c..36579060d8a26 100644 --- a/clang/lib/Driver/SanitizerArgs.cpp +++ b/clang/lib/Driver/SanitizerArgs.cpp @@ -683,8 +683,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, Arg->claim(); if (LegacySanitizeCoverage != 0) { D.Diag(diag::warn_drv_deprecated_arg) - << Arg->getAsString(Args) << true - << "-fsanitize-coverage=trace-pc-guard"; + << Arg->getAsString(Args) << "-fsanitize-coverage=trace-pc-guard"; } continue; } @@ -719,11 +718,11 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, // enabled. if (CoverageFeatures & CoverageTraceBB) D.Diag(clang::diag::warn_drv_deprecated_arg) - << "-fsanitize-coverage=trace-bb" << true + << "-fsanitize-coverage=trace-bb" << "-fsanitize-coverage=trace-pc-guard"; if (CoverageFeatures & Coverage8bitCounters) D.Diag(clang::diag::warn_drv_deprecated_arg) - << "-fsanitize-coverage=8bit-counters" << true + << "-fsanitize-coverage=8bit-counters" << "-fsanitize-coverage=trace-pc-guard"; int InsertionPointTypes = CoverageFunc | CoverageBB | CoverageEdge; @@ -733,7 +732,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, if ((CoverageFeatures & InsertionPointTypes) && !(CoverageFeatures & InstrumentationTypes)) { D.Diag(clang::diag::warn_drv_deprecated_arg) - << "-fsanitize-coverage=[func|bb|edge]" << true + << "-fsanitize-coverage=[func|bb|edge]" << "-fsanitize-coverage=[func|bb|edge],[trace-pc-guard|trace-pc]"; } diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 9856a42e1db53..c77413ddf1ace 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6391,14 +6391,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, options::OPT_fno_assume_sane_operator_new)) CmdArgs.push_back("-fno-assume-sane-operator-new"); - // -frelaxed-template-template-args is deprecated and on by default. - if (Arg *A = - Args.getLastArg(options::OPT_frelaxed_template_template_args, - options::OPT_fno_relaxed_template_template_args)) { - D.Diag(diag::warn_drv_deprecated_arg) << A->getAsString(Args) << false; - if (A->getOption().matches(options::OPT_fno_relaxed_template_template_args)) - CmdArgs.push_back("-fno-relaxed-template-template-args"); - } + // -frelaxed-template-template-args is off by default, as it is a severe + // breaking change until a corresponding change to template partial ordering + // is provided. + if (Args.hasFlag(options::OPT_frelaxed_template_template_args, + options::OPT_fno_relaxed_template_template_args, false)) + CmdArgs.push_back("-frelaxed-template-template-args"); // -fsized-deallocation is off by default, as it is an ABI-breaking change for // most platforms. diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index b796bd341e12b..c3abdf446cfaf 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1890,12 +1890,12 @@ void tools::checkAMDGPUCodeObjectVersion(const Driver &D, // Emit warnings for legacy options even if they are overridden. if (Args.hasArg(options::OPT_mno_code_object_v3_legacy)) - D.Diag(diag::warn_drv_deprecated_arg) - << "-mno-code-object-v3" << true << "-mcode-object-version=2"; + D.Diag(diag::warn_drv_deprecated_arg) << "-mno-code-object-v3" + << "-mcode-object-version=2"; if (Args.hasArg(options::OPT_mcode_object_v3_legacy)) - D.Diag(diag::warn_drv_deprecated_arg) - << "-mcode-object-v3" << true << "-mcode-object-version=3"; + D.Diag(diag::warn_drv_deprecated_arg) << "-mcode-object-v3" + << "-mcode-object-version=3"; if (auto *CodeObjArg = getAMDGPUCodeObjectArgument(D, Args)) { if (CodeObjArg->getOption().getID() == diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index aed96e1f404fc..6ff87eb61bf79 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -7407,7 +7407,9 @@ bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, // C++1z [temp.arg.template]p3: (DR 150) // A template-argument matches a template template-parameter P when P // is at least as specialized as the template-argument A. - // FIXME: RelaxedTemplateTemplateArgs is deprecated, should be always on. + // FIXME: We should enable RelaxedTemplateTemplateArgs by default as it is a + // defect report resolution from C++17 and shouldn't be introduced by + // concepts. if (getLangOpts().RelaxedTemplateTemplateArgs) { // Quick check for the common case: // If P contains a parameter pack, then A [...] matches P if each of A's diff --git a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp index 2acdc2ca96b8e..8e69f134a3d14 100644 --- a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp +++ b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -std=c++2a -verify %s +// RUN: %clang_cc1 -std=c++2a -frelaxed-template-template-args -verify %s template<typename T> concept C = T::f(); // expected-note@-1{{similar constraint}} diff --git a/clang/test/Driver/frelaxed-template-template-args.cpp b/clang/test/Driver/frelaxed-template-template-args.cpp deleted file mode 100644 index dd6265ba8375e..0000000000000 --- a/clang/test/Driver/frelaxed-template-template-args.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// RUN: %clang -fsyntax-only -frelaxed-template-template-args %s 2>&1 | FileCheck --check-prefix=CHECK-ON %s -// RUN: %clang -fsyntax-only -fno-relaxed-template-template-args %s 2>&1 | FileCheck --check-prefix=CHECK-OFF %s - -// CHECK-ON: warning: argument '-frelaxed-template-template-args' is deprecated [-Wdeprecated] -// CHECK-OFF: warning: argument '-fno-relaxed-template-template-args' is deprecated [-Wdeprecated] diff --git a/clang/test/Lexer/cxx-features.cpp b/clang/test/Lexer/cxx-features.cpp index a36986c2551b2..40c73f6019420 100644 --- a/clang/test/Lexer/cxx-features.cpp +++ b/clang/test/Lexer/cxx-features.cpp @@ -5,7 +5,7 @@ // RUN: %clang_cc1 -std=c++20 -fcxx-exceptions -fsized-deallocation -verify %s // RUN: %clang_cc1 -std=c++2b -fcxx-exceptions -fsized-deallocation -verify %s // -// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -fno-relaxed-template-template-args -DNO_RELAXED_TEMPLATE_TEMPLATE_ARGS=1 -verify %s +// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -frelaxed-template-template-args -DRELAXED_TEMPLATE_TEMPLATE_ARGS=1 -verify %s // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -DCONCEPTS_TS=1 -verify %s // RUN: %clang_cc1 -std=c++14 -fno-rtti -fno-threadsafe-statics -verify %s -DNO_EXCEPTIONS -DNO_RTTI -DNO_THREADSAFE_STATICS -fsized-deallocation // RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -DNO_EXCEPTIONS -DCOROUTINES -verify -fsized-deallocation %s @@ -195,9 +195,9 @@ #error "wrong value for __cpp_nontype_template_args" #endif -#if defined(NO_RELAXED_TEMPLATE_TEMPLATE_ARGS) \ - ? check(template_template_args, 0, 0, 0, 0, 0, 0) \ - : check(template_template_args, 201611, 201611, 201611, 201611, 201611, 201611) +#if defined(RELAXED_TEMPLATE_TEMPLATE_ARGS) \ + ? check(template_template_args, 0, 0, 0, 201611, 201611, 201611) \ + : check(template_template_args, 0, 0, 0, 0, 0, 0) #error "wrong value for __cpp_template_template_args" #endif diff --git a/clang/test/SemaTemplate/deduction.cpp b/clang/test/SemaTemplate/deduction.cpp index 964f8b4896e7a..9c75595bc74a5 100644 --- a/clang/test/SemaTemplate/deduction.cpp +++ b/clang/test/SemaTemplate/deduction.cpp @@ -60,14 +60,12 @@ struct Replace<const T, Arg1, Arg2> { // Replacement of templates template<template<typename> class TT, typename T1, typename Arg1, typename Arg2> struct Replace<TT<T1>, Arg1, Arg2> { -// expected-note@-1 2 {{partial specialization matches}} typedef TT<typename Replace<T1, Arg1, Arg2>::type> type; }; template<template<typename, typename> class TT, typename T1, typename T2, typename Arg1, typename Arg2> struct Replace<TT<T1, T2>, Arg1, Arg2> { -// expected-note@-1 2 {{partial specialization matches}} typedef TT<typename Replace<T1, Arg1, Arg2>::type, typename Replace<T2, Arg1, Arg2>::type> type; }; @@ -81,19 +79,8 @@ struct Replace<TT<T1, _2>, Arg1, Arg2> { int array0[is_same<Replace<_1, int, float>::type, int>::value? 1 : -1]; int array1[is_same<Replace<const _1, int, float>::type, const int>::value? 1 : -1]; - int array2[is_same<Replace<vector<_1>, int, float>::type, vector<int> >::value? 1 : -1]; -// expected-error@-1 {{ambiguous partial specializations of 'Replace<vector<_1>, int, float>'}} -// FIXME: Some bad error recovery from the parser here: -// expected-error@-3 {{expected '(' for function-style cast or type construction}} -// expected-error@-4 {{no member named 'value' in the global namespace}} - int array3[is_same<Replace<vector<const _1>, int, float>::type, vector<const int> >::value? 1 : -1]; -// expected-error@-1 {{ambiguous partial specializations of 'Replace<vector<const _1>, int, float>'}} -// FIXME: Some bad error recovery from the parser here: -// expected-error@-3 {{expected '(' for function-style cast or type construction}} -// expected-error@-4 {{no member named 'value' in the global namespace}} - int array4[is_same<Replace<vector<int, _2>, double, float>::type, vector<int, float> >::value? 1 : -1]; // PR5911 diff --git a/clang/test/SemaTemplate/default-arguments.cpp b/clang/test/SemaTemplate/default-arguments.cpp index 84178b7e26d14..882b279de1d08 100644 --- a/clang/test/SemaTemplate/default-arguments.cpp +++ b/clang/test/SemaTemplate/default-arguments.cpp @@ -112,14 +112,15 @@ template<typename T, template<typename> class X = T::template apply> int array4[is_same<X4<add_pointer>, X4<add_pointer, add_pointer::apply> >::value? 1 : -1]; -template<int> struct X5 {}; +template<int> struct X5 {}; // expected-note{{has a diff erent type 'int'}} template<long> struct X5b {}; template<typename T, - template<T> class B = X5> + template<T> class B = X5> // expected-error{{template template argument has diff erent}} \ + // expected-note{{previous non-type template parameter}} struct X6 {}; X6<int> x6a; -X6<long> x6b; +X6<long> x6b; // expected-note{{while checking a default template argument}} X6<long, X5b> x6c; diff --git a/clang/test/SemaTemplate/instantiate-template-template-parm.cpp b/clang/test/SemaTemplate/instantiate-template-template-parm.cpp index f97e5b7c548e8..a70c7e8b081a4 100644 --- a/clang/test/SemaTemplate/instantiate-template-template-parm.cpp +++ b/clang/test/SemaTemplate/instantiate-template-template-parm.cpp @@ -20,29 +20,30 @@ apply<add_reference, int>::type ir = i; 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'}} // Template template parameters -template<int> struct B; +template<int> struct B; // expected-note{{has a diff erent type 'int'}} template<typename T, - template<T Value> class X> // expected-error{{cannot have type 'float'}} + template<T Value> class X> // expected-error{{cannot have type 'float'}} \ + // expected-note{{with type 'long'}} struct X0 { }; X0<int, B> x0b1; X0<float, B> x0b2; // expected-note{{while substituting}} -X0<long, B> x0b3; +X0<long, B> x0b3; // expected-error{{template template argument has diff erent template parameters}} -template<template<int V> class TT> +template<template<int V> class TT> // expected-note{{parameter with type 'int'}} struct X1 { }; template<typename T, template<T V> class TT> struct X2 { - X1<TT> x1; + X1<TT> x1; // expected-error{{has diff erent template parameters}} }; template<int V> struct X3i { }; -template<long V> struct X3l { }; +template<long V> struct X3l { }; // expected-note{{ diff erent type 'long'}} X2<int, X3i> x2okay; -X2<long, X3l> x2bad; +X2<long, X3l> x2bad; // expected-note{{instantiation}} template <typename T, template <T, T> class TT, class R = TT<1, 2> > struct Comp { diff --git a/clang/test/SemaTemplate/nested-template.cpp b/clang/test/SemaTemplate/nested-template.cpp index 5bd388d4dff3d..efbde2076b9fa 100644 --- a/clang/test/SemaTemplate/nested-template.cpp +++ b/clang/test/SemaTemplate/nested-template.cpp @@ -112,16 +112,18 @@ template struct X1<int>::B<bool>; // Template template parameters template<typename T> struct X2 { - template<template<class U, T Value> class> // expected-error{{cannot have type 'float'}} + template<template<class U, T Value> class> // expected-error{{cannot have type 'float'}} \ + // expected-note{{previous non-type template}} struct Inner { }; }; -template<typename T, int Value> +template<typename T, + int Value> // expected-note{{template non-type parameter}} struct X2_arg; X2<int>::Inner<X2_arg> x2i1; X2<float> x2a; // expected-note{{instantiation}} -X2<long>::Inner<X2_arg> x2i3; +X2<long>::Inner<X2_arg> x2i3; // expected-error{{template template argument has diff erent}} namespace PR10896 { template<typename TN> diff --git a/clang/test/SemaTemplate/temp_arg_template.cpp b/clang/test/SemaTemplate/temp_arg_template.cpp index 42926fa368929..37e1e52521263 100644 --- a/clang/test/SemaTemplate/temp_arg_template.cpp +++ b/clang/test/SemaTemplate/temp_arg_template.cpp @@ -6,11 +6,11 @@ template<template<typename T> class X> struct A; // expected-note 2{{previous te template<template<typename T, int I> class X> struct B; // expected-note{{previous template template parameter is here}} -template<template<int I> class X> struct C; // expected-note {{previous non-type template parameter with type 'int' is here}} +template<template<int I> class X> struct C; // expected-note 2{{previous non-type template parameter with type 'int' is here}} template<class> struct X; // expected-note{{too few template parameters in template template argument}} template<int N> struct Y; // expected-note{{template parameter has a diff erent kind in template argument}} -template<long N> struct Ylong; +template<long N> struct Ylong; // expected-note{{template non-type parameter has a diff erent type 'long' in template argument}} template<const int &N> struct Yref; // expected-note{{template non-type parameter has a diff erent type 'const int &' in template argument}} namespace N { @@ -27,7 +27,7 @@ A<Y> *a4; // expected-error{{template template argument has diff erent template p A<TooMany> *a5; // expected-error{{template template argument has diff erent template parameters than its corresponding template template parameter}} B<X> *a6; // expected-error{{template template argument has diff erent template parameters than its corresponding template template parameter}} C<Y> *a7; -C<Ylong> *a8; +C<Ylong> *a8; // expected-error{{template template argument has diff erent template parameters than its corresponding template template parameter}} C<Yref> *a9; // expected-error{{template template argument has diff erent template parameters than its corresponding template template parameter}} template<typename T> void f(int); diff --git a/clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp b/clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp index 372a00efc601e..03ef78f8cf14e 100644 --- a/clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp +++ b/clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -frelaxed-template-template-args %s // expected-note@temp_arg_template_cxx1z.cpp:* 1+{{}} diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html index db30a79a634ad..6894ca1b1ea64 100755 --- a/clang/www/cxx_status.html +++ b/clang/www/cxx_status.html @@ -596,7 +596,7 @@ <h2 id="cxx17">C++17 implementation status</h2> <p>You can use Clang in C++17 mode with the <code>-std=c++17</code> option (use <code>-std=c++1z</code> in Clang 4 and earlier).</p> -<details> +<details open> <summary>List of features and minimum Clang version with support</summary> <table width="689" border="1" cellspacing="0"> @@ -813,8 +813,8 @@ <h2 id="cxx17">C++17 implementation status</h2> <!-- Issaquah 2016 papers --> <tr> <td>Matching template template parameters to compatible arguments</td> - <td><a href="https://wg21.link/p0522r0">P0522R0</a> (<a href="#dr">DR</a>)</td> - <td class="full" align="center">Clang 4 <a href="#p0522">(10)</a></td> + <td><a href="https://wg21.link/p0522r0">P0522R0</a></td> + <td class="partial" align="center">Partial <a href="#p0522">(10)</a></td> </tr> <tr> <td>Removing deprecated dynamic exception specifications</td> @@ -842,10 +842,13 @@ <h2 id="cxx17">C++17 implementation status</h2> reverse construction order in that ABI. This is not fully supported during constant expression evaluation until Clang 12. </span><br> -<span id="p0522">(10): Prior to Clang 14, this feature is not enabled by -default, but can be enabled with <tt>-frelaxed-template-template-args</tt>. -Starting from Clang 14, the flag is deprecated and will be removed in a future -version. +<span id="p0522">(10): Despite being the resolution to a Defect Report, this +feature is disabled by default in all language versions, and can be enabled +explicitly with the flag <tt>-frelaxed-template-template-args</tt> in Clang 4 +onwards. +The change to the standard lacks a corresponding change for template partial +ordering, resulting in ambiguity errors for reasonable and previously-valid +code. This issue is expected to be rectified soon. </span> </p> </details> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits