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

> On Tue, Mar 20, 2018 at 5:57 PM, Alexandre Oliva <aol...@redhat.com> wrote:
>> On Mar 20, 2018, Jason Merrill <ja...@redhat.com> wrote:
> Let's put this in cp-tree.h, with warning_sentinel.

>> +  (void)cleanup;

> There are lots of RAII variables without this explicit cast to void,
> and they don't seem to have been a problem; let's drop it here as
> well.

Done, here's what passed regstrap on i686- and x86_64-linux-gnu last
night.  Ok to install?

Disable auto_is_implicit_function_template_parm_p while parsing attributes

for  gcc/cp/ChangeLog

        PR c++/84610
        PR c++/84642
        * cp-tree.h (temp_override): New template class, generalizing
        a cleanup that was only used...
        * parser.c (cp_parser_parameter_declaration_clause):
        ... here for auto_is_implicit_function_template_parm_p.
        (cp_parser_gnu_attributes_opt): Use it here as well.
        (cp_parser_std_attribute): Likewise.
---
 gcc/cp/cp-tree.h |   19 +++++++++++++++++++
 gcc/cp/parser.c  |   18 ++++++++----------
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index c07aaa5781ac..c8f4bc43fa3c 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -1657,6 +1657,25 @@ struct warning_sentinel
   ~warning_sentinel() { flag = val; }
 };
 
+/* RAII sentinel that saves the value of a variable, optionally
+   overrides it right away, and restores its value when the sentinel
+   id destructed.  */
+
+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; }
+};
+
 /* The cached class binding level, from the most recently exited
    class, or NULL if none.  */
 
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 6dcfae125b7b..34619293120b 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -21196,16 +21196,8 @@ 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);
 
   if (!processing_specialization
       && !processing_template_parmlist
@@ -24968,6 +24960,9 @@ 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);
+
   while (true)
     {
       cp_token *token;
@@ -25159,6 +25154,9 @@ 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);
+
   /* 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 via email to