]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix ICE-after-error on partial spec [92068]
authorJason Merrill <jason@redhat.com>
Sat, 14 Mar 2020 21:10:39 +0000 (17:10 -0400)
committerJason Merrill <jason@redhat.com>
Sun, 15 Mar 2020 09:47:28 +0000 (05:47 -0400)
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  <jason@redhat.com>

PR c++/92068
* pt.c (process_partial_specialization): Error rather than crash on
extra pack expansion.

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp0x/variadic178.C [new file with mode: 0644]

index 0bc9e12014d69d74c99ce24d14316dad85bd20a6..e81e39d177066b1218e6da8873ab9302a9de77e5 100644 (file)
@@ -1,3 +1,9 @@
+2020-03-14  Jason Merrill  <jason@redhat.com>
+
+       PR c++/92068
+       * pt.c (process_partial_specialization): Error rather than crash on
+       extra pack expansion.
+
 2020-03-14  Jason Merrill  <jason@redhat.com>
 
        PR c++/93248
index a12da5ef86663638e0c69963d6471ac0f5f2e972..2ceace5ea1a8256a696be21d37d91fd51808be11 100644 (file)
@@ -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 (file)
index 0000000..f0e6595
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/92068
+// { dg-do compile { target c++11 } }
+
+template <typename, typename> struct a;
+template <typename b, typename c, typename... d>
+struct a<b, c, d...> { };      // { dg-error "arguments" }