From: Jason Merrill Date: Sat, 14 Mar 2020 21:10:39 +0000 (-0400) Subject: c++: Fix ICE-after-error on partial spec [92068] X-Git-Tag: embedded-9-2020q2~107 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2fa5f9e380b794053a0dd8a8cc63f8bfab370d22;p=thirdparty%2Fgcc.git c++: Fix ICE-after-error on partial spec [92068] Here the template arguments for the partial specialization are valid arguments for the template, but not for a partial specialization, because 'd' can never be deduced to anything other than an empty pack. gcc/cp/ChangeLog 2020-03-14 Jason Merrill PR c++/92068 * pt.c (process_partial_specialization): Error rather than crash on extra pack expansion. --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0bc9e12014d6..e81e39d17706 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2020-03-14 Jason Merrill + + PR c++/92068 + * pt.c (process_partial_specialization): Error rather than crash on + extra pack expansion. + 2020-03-14 Jason Merrill PR c++/93248 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index a12da5ef8666..2ceace5ea1a8 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -4877,6 +4877,14 @@ process_partial_specialization (tree decl) return decl; } + else if (nargs > DECL_NTPARMS (maintmpl)) + { + error ("too many arguments for partial specialization %qT", type); + inform (DECL_SOURCE_LOCATION (maintmpl), "primary template here"); + /* Avoid crash below. */ + return decl; + } + /* If we aren't in a dependent class, we can actually try deduction. */ else if (tpd.level == 1 /* FIXME we should be able to handle a partial specialization of a @@ -4903,7 +4911,6 @@ process_partial_specialization (tree decl) Also, we verify that pack expansions only occur at the end of the argument list. */ - gcc_assert (nargs == DECL_NTPARMS (maintmpl)); tpd2.parms = 0; for (i = 0; i < nargs; ++i) { diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic178.C b/gcc/testsuite/g++.dg/cpp0x/variadic178.C new file mode 100644 index 000000000000..f0e65958de37 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/variadic178.C @@ -0,0 +1,6 @@ +// PR c++/92068 +// { dg-do compile { target c++11 } } + +template struct a; +template +struct a { }; // { dg-error "arguments" }