public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexandre Oliva <aoliva@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches List <gcc-patches@gcc.gnu.org>,
	       Jakub Jelinek <jakub@redhat.com>
Subject: Re: [PATCH] [PR c++/84610,84642] recover from implicit template parms gracefully
Date: Tue, 20 Mar 2018 21:59:00 -0000	[thread overview]
Message-ID: <orin9ql89y.fsf_-_@lxoliva.fsfla.org> (raw)
In-Reply-To: <CADzB+2nByWYDrCmC069S_YUnFaFmAxyV+zbZfrAi1eXtrWb7bQ@mail.gmail.com>	(Jason Merrill's message of "Tue, 20 Mar 2018 15:43:06 -0400")

On Mar 20, 2018, Jason Merrill <jason@redhat.com> wrote:

>> While debugging this, I first tried another patch, that avoids the same
>> ICEs.  I thought this one was a more complete solution, and it renders
>> the other unnecessary, but I still though it might be useful to disable
>> auto->implicit_parm while parsing declarators, so as to avoid useless
>> processing.

> Better, I think, to disable it while parsing attributes; we could
> still encounter auto as a template argument in a declarator.

How about this?  Regstrapping, ok to install if it passes?

Disable auto_is_implicit_function_template_parm_p while parsing attributes

for  gcc/cp/ChangeLog

	PR c++/84610
	PR c++/84642
	* parser.c (temp_override): New template class,
	generalizing...
	(cp_parser_parameter_declaration_clause): ... this cleanup.
	Use it.
	(cp_parser_gnu_attributes_opt): Use it.
	(cp_parser_std_attribute): Use it.
---
 gcc/cp/parser.c |   36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 5cc201604166..ce05615adfba 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -255,6 +255,21 @@ static bool cp_parser_omp_declare_reduction_exprs
 static void cp_finalize_oacc_routine
   (cp_parser *, tree, bool);
 
+template <typename T>
+class temp_override
+{
+  T& overridden_variable;
+  T saved_value;
+public:
+  temp_override(T& var) : overridden_variable (var), saved_value (var) {}
+  temp_override(T& var, T overrider)
+    : overridden_variable (var), saved_value (var)
+  {
+    overridden_variable = overrider;
+  }
+  ~temp_override() { overridden_variable = saved_value; }
+};
+
 /* Manifest constants.  */
 #define CP_LEXER_BUFFER_SIZE ((256 * 1024) / sizeof (cp_token))
 #define CP_SAVED_TOKEN_STACK 5
@@ -21187,16 +21202,9 @@ cp_parser_parameter_declaration_clause (cp_parser* parser)
   bool ellipsis_p;
   bool is_error;
 
-  struct cleanup {
-    cp_parser* parser;
-    int auto_is_implicit_function_template_parm_p;
-    ~cleanup() {
-      parser->auto_is_implicit_function_template_parm_p
-	= auto_is_implicit_function_template_parm_p;
-    }
-  } cleanup = { parser, parser->auto_is_implicit_function_template_parm_p };
-
-  (void) cleanup;
+  temp_override<bool> cleanup
+    (parser->auto_is_implicit_function_template_parm_p);
+  (void)cleanup;
 
   if (!processing_specialization
       && !processing_template_parmlist
@@ -24959,6 +24967,10 @@ cp_parser_gnu_attributes_opt (cp_parser* parser)
 {
   tree attributes = NULL_TREE;
 
+  temp_override<bool> cleanup
+    (parser->auto_is_implicit_function_template_parm_p, false);
+  (void)cleanup;
+
   while (true)
     {
       cp_token *token;
@@ -25150,6 +25162,10 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns)
   tree attribute, attr_id = NULL_TREE, arguments;
   cp_token *token;
 
+  temp_override<bool> cleanup
+    (parser->auto_is_implicit_function_template_parm_p, false);
+  (void)cleanup;
+
   /* First, parse name of the attribute, a.k.a attribute-token.  */
 
   token = cp_lexer_peek_token (parser->lexer);


-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer

  reply	other threads:[~2018-03-20 21:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-10 11:57 Alexandre Oliva
2018-03-20 19:46 ` Jason Merrill
2018-03-20 21:59   ` Alexandre Oliva [this message]
2018-03-20 22:08     ` [PATCH] " Jason Merrill
2018-03-21 21:52       ` Alexandre Oliva
2018-03-22 17:51         ` 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=orin9ql89y.fsf_-_@lxoliva.fsfla.org \
    --to=aoliva@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --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).