PR c++/60065
        * parser.c (cp_parser_parameter_declaration_list): Use
        current_template_parms and scope check as predicate for
        inspecting current function template parameter list length
        rather than num_template_parameter_lists.

        PR c++/60065
        * g++.dg/cpp1y/pr60065.C: New testcase.
---
 gcc/cp/parser.c                      | 20 +++++++++++++++++---
 gcc/testsuite/g++.dg/cpp1y/pr60065.C |  8 ++++++++
 2 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/pr60065.C

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 68573f1..0b88bd3 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -18241,15 +18241,29 @@ cp_parser_parameter_declaration_list (cp_parser* 
parser, bool *is_error)
     = parser->in_unbraced_linkage_specification_p;
   parser->in_unbraced_linkage_specification_p = false;
 
+  /* Determine whether this parameter list applies to a function template
+     currently being declared to support extending the template with generic
+     type parameters.  */
+  bool declaring_template_p = false;
+  if (current_template_parms)
+    {
+      cp_binding_level *maybe_tmpl_scope = current_binding_level->level_chain;
+      while (maybe_tmpl_scope && maybe_tmpl_scope->kind == sk_class)
+       maybe_tmpl_scope = maybe_tmpl_scope->level_chain;
+      if (maybe_tmpl_scope && maybe_tmpl_scope->kind == sk_template_parms)
+       declaring_template_p = true;
+    }
+
   /* Look for more parameters.  */
   while (true)
     {
       cp_parameter_declarator *parameter;
       tree decl = error_mark_node;
       bool parenthesized_p = false;
-      int template_parm_idx = (parser->num_template_parameter_lists?
-                              TREE_VEC_LENGTH (INNERMOST_TEMPLATE_PARMS
-                                               (current_template_parms)) : 0);
+      int template_parm_idx =
+       ((declaring_template_p || parser->fully_implicit_function_template_p)?
+        TREE_VEC_LENGTH (INNERMOST_TEMPLATE_PARMS
+                         (current_template_parms)) : 0);
 
       /* Parse the parameter.  */
       parameter
diff --git a/gcc/testsuite/g++.dg/cpp1y/pr60065.C 
b/gcc/testsuite/g++.dg/cpp1y/pr60065.C
new file mode 100644
index 0000000..2aaa1e3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/pr60065.C
@@ -0,0 +1,8 @@
+// PR c++/60065
+// { dg-do compile }
+// { dg-options "-std=c++1y" }
+
+template <int> void foo(auto... x);
+template <typename> void foo2(auto... x);
+template <int> void foo3(auto... x, auto y, auto... z);
+template <typename> void foo4(auto... x, auto y, auto... z);
-- 
1.9.0

Reply via email to