diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 6b63edda60d26a34f2507f3feec979c17f2a46b7..106dfe556f7fd7c9ff2af2cbfbf7f9254316b3cf 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 a58d397ca3fd8e24c5ea6f44934decc61c802af4..4e9632f6a7d4279653859d1b66bbab3cf5b6728e 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 0000000000000000000000000000000000000000..29f25e50c9e894c68a9f37f32d3efdd42776e55b --- /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 <class> struct A { A(int = 0); }; +template <class = void> using B = A<int>; +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 3cb27a85c007df09b97363e7b721f781862df664..3cafd9f1f01a38700b7b646c32bd1be44c2899a1 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 6cae360aa161ac65c9c3a81ecde6d39d6d7d8ac2..de1534cc6373ab9bbb83649c64ac468bc73799aa 100644 --- a/gcc/testsuite/g++.dg/template/error8.C +++ b/gcc/testsuite/g++.dg/template/error8.C @@ -3,6 +3,6 @@ template <typename T> 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 } }