This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/52008 (ICE with variadic partial specialization)

In this testcase, the partial specialization has fewer template arguments than the primary template has parameters, which was confusing GCC. Let's give an error for this case because the partial specialization isn't more specialized than the primary template.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit b7486132b037ea59ac7e6524085e4e765dc22852
Author: Jason Merrill <>
Date:   Mon Apr 16 12:49:13 2012 -0400

    	PR c++/52008
    	* pt.c (process_partial_specialization): Complain about a partial
    	specialization with fewer args than primary template parms.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index fcefc94..d6144d5 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -4376,6 +4376,18 @@ process_partial_specialization (tree decl)
     error ("partial specialization %qT does not specialize any template arguments", type);
+  /* A partial specialization that replaces multiple parameters of the
+     primary template with a pack expansion is less specialized for those
+     parameters.  */
+  if (nargs < DECL_NTPARMS (maintmpl))
+    {
+      error ("partial specialization is not more specialized than the "
+	     "primary template because it replaces multiple parameters "
+	     "with a pack expansion");
+      inform (DECL_SOURCE_LOCATION (maintmpl), "primary template here");
+      return decl;
+    }
   /* [temp.class.spec]
      A partially specialized non-type argument expression shall not
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic130.C b/gcc/testsuite/g++.dg/cpp0x/variadic130.C
new file mode 100644
index 0000000..f73c8b5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic130.C
@@ -0,0 +1,8 @@
+// PR c++/52008
+// { dg-do compile { target c++11 } }
+template <int I, typename T, typename... Ts>
+struct A;
+template<typename... Ts>
+struct A<0, Ts...>;		// { dg-error "not more specialized" }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]