cp-tree.h (struct cp_evaluated): New.
authorJason Merrill <jason@redhat.com>
Tue, 13 Nov 2018 04:33:57 +0000 (23:33 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 13 Nov 2018 04:33:57 +0000 (23:33 -0500)
* cp-tree.h (struct cp_evaluated): New.

This patch simplifies the saving/clearing/restoring of
cp_unevaluated_operand and c_inhibit_evaluation_warnings in the presence of
mid-block returns.

* init.c (get_nsdmi): Use it.
* parser.c (cp_parser_enclosed_template_argument_list): Use it.
* pt.c (coerce_template_parms, tsubst_aggr_type): Use it.

From-SVN: r266051

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/init.c
gcc/cp/parser.c
gcc/cp/pt.c

index cf738cbf0dac565b91728781537c532ec96c2872..066d293e531ef329f226b8af34c7fba3ca538f6c 100644 (file)
@@ -1,3 +1,10 @@
+2018-11-12  Jason Merrill  <jason@redhat.com>
+
+       * cp-tree.h (struct cp_evaluated): New.
+       * init.c (get_nsdmi): Use it.
+       * parser.c (cp_parser_enclosed_template_argument_list): Use it.
+       * pt.c (coerce_template_parms, tsubst_aggr_type): Use it.
+
 2018-11-09  Jakub Jelinek  <jakub@redhat.com>
 
        * parser.c (cp_parser_omp_clause_final, cp_parser_omp_clause_if): Use
index 6ca138d4ce65f72ec4b705bca8de74bae276b947..9c4664c3aa70721aeb40af344eccc785320efdfd 100644 (file)
@@ -5231,6 +5231,21 @@ struct cp_unevaluated
   ~cp_unevaluated ();
 };
 
+/* The reverse: an RAII class used for nested contexts that are evaluated even
+   if the enclosing context is not.  */
+
+struct cp_evaluated
+{
+  int uneval;
+  int inhibit;
+  cp_evaluated ()
+    : uneval(cp_unevaluated_operand), inhibit(c_inhibit_evaluation_warnings)
+  { cp_unevaluated_operand = c_inhibit_evaluation_warnings = 0; }
+  ~cp_evaluated ()
+  { cp_unevaluated_operand = uneval;
+    c_inhibit_evaluation_warnings = inhibit; }
+};
+
 /* in pt.c  */
 
 /* These values are used for the `STRICT' parameter to type_unification and
index 15046b4257bc7aac7b561801820ff997d71e123c..a17e1608c80a2cf9613fc49afd55411f3b292413 100644 (file)
@@ -569,8 +569,7 @@ get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain)
        }
       else
        {
-         int un = cp_unevaluated_operand;
-         cp_unevaluated_operand = 0;
+         cp_evaluated ev;
 
          location_t sloc = input_location;
          input_location = expr_loc;
@@ -616,7 +615,6 @@ get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain)
            }
 
          input_location = sloc;
-         cp_unevaluated_operand = un;
        }
     }
   else
index 1766ef418a2204ccc87a70fea7bee9cb7aa4419d..465ab8fdbaed0efbaa68a8583dac908ce6c72f9e 100644 (file)
@@ -27861,8 +27861,6 @@ cp_parser_enclosed_template_argument_list (cp_parser* parser)
   tree saved_qualifying_scope;
   tree saved_object_scope;
   bool saved_greater_than_is_operator_p;
-  int saved_unevaluated_operand;
-  int saved_inhibit_evaluation_warnings;
 
   /* [temp.names]
 
@@ -27879,10 +27877,7 @@ cp_parser_enclosed_template_argument_list (cp_parser* parser)
   saved_object_scope = parser->object_scope;
   /* We need to evaluate the template arguments, even though this
      template-id may be nested within a "sizeof".  */
-  saved_unevaluated_operand = cp_unevaluated_operand;
-  cp_unevaluated_operand = 0;
-  saved_inhibit_evaluation_warnings = c_inhibit_evaluation_warnings;
-  c_inhibit_evaluation_warnings = 0;
+  cp_evaluated ev;
   /* Parse the template-argument-list itself.  */
   if (cp_lexer_next_token_is (parser->lexer, CPP_GREATER)
       || cp_lexer_next_token_is (parser->lexer, CPP_RSHIFT))
@@ -27951,8 +27946,6 @@ cp_parser_enclosed_template_argument_list (cp_parser* parser)
   parser->scope = saved_scope;
   parser->qualifying_scope = saved_qualifying_scope;
   parser->object_scope = saved_object_scope;
-  cp_unevaluated_operand = saved_unevaluated_operand;
-  c_inhibit_evaluation_warnings = saved_inhibit_evaluation_warnings;
 
   return arguments;
 }
index d4ae76a89f4f4f2aeb092a3f8c9e1ca060832b23..4cb8238ba121f8461bf511fb57844eee90cea1cf 100644 (file)
@@ -8256,8 +8256,6 @@ coerce_template_parms (tree parms,
   tree inner_args;
   tree new_args;
   tree new_inner_args;
-  int saved_unevaluated_operand;
-  int saved_inhibit_evaluation_warnings;
 
   /* When used as a boolean value, indicates whether this is a
      variadic template parameter list. Since it's an int, we can also
@@ -8374,10 +8372,8 @@ coerce_template_parms (tree parms,
 
   /* We need to evaluate the template arguments, even though this
      template-id may be nested within a "sizeof".  */
-  saved_unevaluated_operand = cp_unevaluated_operand;
-  cp_unevaluated_operand = 0;
-  saved_inhibit_evaluation_warnings = c_inhibit_evaluation_warnings;
-  c_inhibit_evaluation_warnings = 0;
+  cp_evaluated ev;
+
   new_inner_args = make_tree_vec (nparms);
   new_args = add_outermost_template_args (args, new_inner_args);
   int pack_adjust = 0;
@@ -8517,8 +8513,6 @@ coerce_template_parms (tree parms,
        lost++;
       TREE_VEC_ELT (new_inner_args, arg_idx - pack_adjust) = arg;
     }
-  cp_unevaluated_operand = saved_unevaluated_operand;
-  c_inhibit_evaluation_warnings = saved_inhibit_evaluation_warnings;
 
   if (missing || arg_idx < nargs - variadic_args_p)
     {
@@ -12655,14 +12649,9 @@ tsubst_aggr_type (tree t,
          tree argvec;
          tree context;
          tree r;
-         int saved_unevaluated_operand;
-         int saved_inhibit_evaluation_warnings;
 
          /* In "sizeof(X<I>)" we need to evaluate "I".  */
-         saved_unevaluated_operand = cp_unevaluated_operand;
-         cp_unevaluated_operand = 0;
-         saved_inhibit_evaluation_warnings = c_inhibit_evaluation_warnings;
-         c_inhibit_evaluation_warnings = 0;
+         cp_evaluated ev;
 
          /* First, determine the context for the type we are looking
             up.  */
@@ -12696,9 +12685,6 @@ tsubst_aggr_type (tree t,
              r = cp_build_qualified_type_real (r, cp_type_quals (t), complain);
            }
 
-         cp_unevaluated_operand = saved_unevaluated_operand;
-         c_inhibit_evaluation_warnings = saved_inhibit_evaluation_warnings;
-
          return r;
        }
       else