PR c++/85093 - too many template args with pack expansion.
authorJason Merrill <jason@redhat.com>
Thu, 29 Mar 2018 19:38:41 +0000 (15:38 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 29 Mar 2018 19:38:41 +0000 (15:38 -0400)
* pt.c (coerce_template_parms): Keep pack expansion args that will
need to be empty.

From-SVN: r258964

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

index cc950e8d74e6ca3ba5c4f32042353409ab147199..1536c359fe8adcf45817e6cc8aa45ee288e0e150 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-29  Jason Merrill  <jason@redhat.com>
+
+       PR c++/85093 - too many template args with pack expansion.
+       * pt.c (coerce_template_parms): Keep pack expansion args that will
+       need to be empty.
+
 2018-03-29  Jason Merrill  <jason@redhat.com>
 
        * pt.c (build_non_dependent_expr): Propagate expr location.
index 40ddf9ec989b5ef9943bc432951135e461d0a8ef..284eaf3cab66e04f6ccdf15ffa70e53f3b855828 100644 (file)
@@ -8497,6 +8497,22 @@ coerce_template_parms (tree parms,
       goto bad_nargs;
     }
 
+  if (arg_idx < nargs)
+    {
+      /* We had some pack expansion arguments that will only work if the packs
+        are empty, but wait until instantiation time to complain.
+        See variadic-ttp3.C.  */
+      int len = nparms + (nargs - arg_idx);
+      tree args = make_tree_vec (len);
+      int i = 0;
+      for (; i < nparms; ++i)
+       TREE_VEC_ELT (args, i) = TREE_VEC_ELT (new_inner_args, i);
+      for (; i < len; ++i, ++arg_idx)
+       TREE_VEC_ELT (args, i) = TREE_VEC_ELT (inner_args,
+                                              arg_idx - pack_adjust);
+      new_inner_args = args;
+    }
+
   if (lost)
     {
       gcc_assert (!(complain & tf_error) || seen_error ());
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic-empty1.C b/gcc/testsuite/g++.dg/cpp0x/variadic-empty1.C
new file mode 100644 (file)
index 0000000..42daeaa
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/85093
+// { dg-do compile { target c++11 } }
+
+template<class V> class A {};
+
+template<class V, class... G> class B {
+  typedef A<V,G...> AB;                // { dg-error "arguments" }
+  AB ab;
+};
+
+int main() {
+  B<int,double> b;  
+}