From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 2E9F2394740F; Tue, 13 Apr 2021 16:36:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E9F2394740F MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8155] c++: Reject alias CTAD in C++17 [PR99008] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: 989e512f719a44fafca0030d7b8a1f5bf5f1baf7 X-Git-Newrev: 8913b2c2bcded39427ff27e6dfc276ae8555f6b8 Message-Id: <20210413163636.2E9F2394740F@sourceware.org> Date: Tue, 13 Apr 2021 16:36:36 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Apr 2021 16:36:36 -0000 https://gcc.gnu.org/g:8913b2c2bcded39427ff27e6dfc276ae8555f6b8 commit r11-8155-g8913b2c2bcded39427ff27e6dfc276ae8555f6b8 Author: Patrick Palka Date: Tue Apr 13 12:35:33 2021 -0400 c++: Reject alias CTAD in C++17 [PR99008] Here, in C++17 mode, we only pedwarn about the use of alias CTAD and then later ICE from alias_ctad_tweaks when attempting to constrain the guides. Since the construction of the guides of an alias template effectively relies on concepts, we shouldn't be permissive about alias CTAD in C++17 mode, so this patch turns the pertinent pedwarn in do_class_deduction into an error. In order to get a consistent diagnostic for B() vs the other forms in the added testcase, I had to remove the special handling of CTAD with empty initializer in build_functional_cast_1 so that we always pass 'complain' to do_auto_deduction. gcc/cp/ChangeLog: PR c++/99008 * pt.c (do_class_deduction): Reject alias CTAD in C++17 mode rather than issuing a pedwarn. * typeck2.c (build_functional_cast_1): Handle CTAD uniformly for consistent diagnostics. gcc/testsuite/ChangeLog: PR c++/99008 * g++.dg/parse/template2.C: Adjust expected diagnostic. * g++.dg/template/error8.C: Likewise. * g++.dg/cpp1z/class-deduction84.C: New test. Diff: --- gcc/cp/pt.c | 8 ++++---- gcc/cp/typeck2.c | 17 +++-------------- gcc/testsuite/g++.dg/cpp1z/class-deduction84.C | 9 +++++++++ gcc/testsuite/g++.dg/parse/template2.C | 2 +- gcc/testsuite/g++.dg/template/error8.C | 2 +- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 6b63edda60d..106dfe556f7 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -29305,10 +29305,10 @@ do_class_deduction (tree ptype, tree tmpl, tree init, } else if (cxx_dialect < cxx20 && DECL_ALIAS_TEMPLATE_P (tmpl)) { - /* This doesn't affect conforming C++17 code, so just pedwarn. */ - if (complain & tf_warning_or_error) - pedwarn (input_location, 0, "alias template deduction only available " - "with %<-std=c++20%> or %<-std=gnu++20%>"); + if (complain & tf_error) + error ("alias template deduction only available " + "with %<-std=c++20%> or %<-std=gnu++20%>"); + return error_mark_node; } tree type = TREE_TYPE (tmpl); diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index a58d397ca3f..4e9632f6a7d 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -2197,24 +2197,13 @@ build_functional_cast_1 (location_t loc, tree exp, tree parms, error_at (loc, "invalid use of %qT", anode); return error_mark_node; } - else if (!parms) + else { - /* Even if there are no parameters, we might be able to deduce from - default template arguments. Pass TF_NONE so that we don't - generate redundant diagnostics. */ - type = do_auto_deduction (type, parms, anode, tf_none, + type = do_auto_deduction (type, parms, anode, complain, adc_variable_type); if (type == error_mark_node) - { - if (complain & tf_error) - error_at (loc, "cannot deduce template arguments " - "for %qT from %<()%>", anode); - return error_mark_node; - } + return error_mark_node; } - else - type = do_auto_deduction (type, parms, anode, complain, - adc_variable_type); } if (processing_template_decl) diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction84.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction84.C new file mode 100644 index 00000000000..29f25e50c9e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction84.C @@ -0,0 +1,9 @@ +// PR c++/99008 +// { dg-do compile { target c++17 } } + +template struct A { A(int = 0); }; +template using B = A; +auto x = B{}; // { dg-error "alias template deduction only available with" "" { target c++17_only } } +auto y = B(); // { dg-error "alias template deduction only available with" "" { target c++17_only } } +auto z = B{1}; // { dg-error "alias template deduction only available with" "" { target c++17_only } } +auto w = B(1); // { dg-error "alias template deduction only available with" "" { target c++17_only } } diff --git a/gcc/testsuite/g++.dg/parse/template2.C b/gcc/testsuite/g++.dg/parse/template2.C index 3cb27a85c00..3cafd9f1f01 100644 --- a/gcc/testsuite/g++.dg/parse/template2.C +++ b/gcc/testsuite/g++.dg/parse/template2.C @@ -3,6 +3,6 @@ namespace N { } int main() { - N::C(); // { dg-error "6:cannot deduce template arguments" "" { target c++17 } } + N::C(); // { dg-error "8:class template argument deduction failed|no match" "" { target c++17 } } // { dg-error "7:missing template arguments" "" { target c++14_down } .-1 } } diff --git a/gcc/testsuite/g++.dg/template/error8.C b/gcc/testsuite/g++.dg/template/error8.C index 6cae360aa16..de1534cc637 100644 --- a/gcc/testsuite/g++.dg/template/error8.C +++ b/gcc/testsuite/g++.dg/template/error8.C @@ -3,6 +3,6 @@ template struct S {}; void f() { - throw S (); // { dg-error "9:cannot deduce template arguments" "" { target c++17 } } + throw S (); // { dg-error "12:class template argument deduction failed|no match" "" { target c++17 } } // { dg-error "11:missing template arguments" "" { target c++14_down } .-1 } }