* [C++ PATCH] Fix ICE on operator"" template (PR c++/77638)
@ 2016-09-19 21:59 Jakub Jelinek
2016-09-20 15:18 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2016-09-19 21:59 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
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 <jakub@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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ PATCH] Fix ICE on operator"" template (PR c++/77638)
2016-09-19 21:59 [C++ PATCH] Fix ICE on operator"" template (PR c++/77638) Jakub Jelinek
@ 2016-09-20 15:18 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2016-09-20 15:18 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches List
OK.
On Mon, Sep 19, 2016 at 5:54 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> 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 <jakub@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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-20 15:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-19 21:59 [C++ PATCH] Fix ICE on operator"" template (PR c++/77638) Jakub Jelinek
2016-09-20 15:18 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).