[C++ PATCH] * cp-tree.h (struct cp_evaluated): New.

Jason Merrill jason@redhat.com
Tue Nov 13 04:33:00 GMT 2018


This patch simplifies the saving/clearing/restoring of
cp_unevaluated_operand and c_inhibit_evaluation_warnings in the presence of
mid-block returns.  This cleanup was motivated by the forthcoming
unevaluated lambdas patch.

Tested x86_64-pc-linux-gnu, applying to trunk.

	* 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.
---
 gcc/cp/cp-tree.h | 15 +++++++++++++++
 gcc/cp/init.c    |  4 +---
 gcc/cp/parser.c  |  9 +--------
 gcc/cp/pt.c      | 20 +++-----------------
 gcc/cp/ChangeLog |  7 +++++++
 5 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 6ca138d4ce6..9c4664c3aa7 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -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
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 15046b4257b..a17e1608c80 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -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
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 1766ef418a2..465ab8fdbae 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -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;
 }
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index d4ae76a89f4..4cb8238ba12 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -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
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index cf738cbf0da..066d293e531 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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

base-commit: 2207ad3ae604699984f54ec1fef45c7c35d89b13
-- 
2.17.2



More information about the Gcc-patches mailing list