public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [C++ PATCH] Fix ICE on operator"" template (PR c++/77638)
Date: Mon, 19 Sep 2016 21:59:00 -0000	[thread overview]
Message-ID: <20160919215426.GQ7282@tucnak.redhat.com> (raw)

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

             reply	other threads:[~2016-09-19 21:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-19 21:59 Jakub Jelinek [this message]
2016-09-20 15:18 ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160919215426.GQ7282@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).