From: Jason Merrill Date: Tue, 13 Nov 2018 04:33:57 +0000 (-0500) Subject: cp-tree.h (struct cp_evaluated): New. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=16e723e600a62428b8ed6ab414931ec7a78aceee;p=gcc.git cp-tree.h (struct cp_evaluated): New. * 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 --- 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 + + * 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 * parser.c (cp_parser_omp_clause_final, cp_parser_omp_clause_if): Use 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)" 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