Hi!

As the testcase shows for C++14 and up, for 1 argument template we don't ICE
even if the template argument is invalid, because it checks
  if (TREE_TYPE (parm) != char_type_node
      || !TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))
and if parm is error_mark_node, then it doesn't have char_type_node type.
But, for 2 argument template, if both the template arguments have
error_mark_node type the type test succeeds and we ICE, because DEC_INITIAL
on error_mark_node is not valid.

The following testcase fixes the ICE and results in the same diagnostics
that used to be emitted for C++11 already before the patch.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-09-19  Jakub Jelinek  <ja...@redhat.com>

        PR c++/77638
        * parser.c (cp_parser_template_declaration_after_parameter): For 2
        argument operator"" template set ok to false for
        parm == error_mark_node.

        * g++.dg/cpp0x/udlit-tmpl-arg-neg2.C: New test.

--- gcc/cp/parser.c.jj  2016-09-19 10:33:51.000000000 +0200
+++ gcc/cp/parser.c     2016-09-19 11:29:25.724937375 +0200
@@ -25722,7 +25722,8 @@ cp_parser_template_declaration_after_par
              tree type = INNERMOST_TEMPLATE_PARMS (parm_type);
              tree parm_list = TREE_VEC_ELT (parameter_list, 1);
              tree parm = INNERMOST_TEMPLATE_PARMS (parm_list);
-             if (TREE_TYPE (parm) != TREE_TYPE (type)
+             if (parm == error_mark_node
+                 || TREE_TYPE (parm) != TREE_TYPE (type)
                  || !TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))
                ok = false;
            }
--- gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg2.C.jj 2016-09-19 
11:34:58.680674929 +0200
+++ gcc/testsuite/g++.dg/cpp0x/udlit-tmpl-arg-neg2.C    2016-09-19 
11:33:54.000000000 +0200
@@ -0,0 +1,7 @@
+// PR c++/77638
+// { dg-do compile { target c++11 } }
+
+template <T, T... U>           // { dg-error "'T' has not been declared" }
+int operator"" _foo ();                // { dg-error "has invalid parameter 
list" }
+template <T... U>              // { dg-error "'T' has not been declared" }
+int operator"" _bar ();                // { dg-error "has invalid parameter 
list" }

        Jakub

Reply via email to