diff options
author | Jason Merrill <jason@redhat.com> | 2018-11-12 23:33:57 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2018-11-12 23:33:57 -0500 |
commit | 16e723e600a62428b8ed6ab414931ec7a78aceee (patch) | |
tree | 7e0cf797774e91ae6a17d137439115ace9acb318 /gcc/cp | |
parent | e4bd6d5e1f4496e06ac2d08effa977b191b91a54 (diff) | |
download | gcc-16e723e600a62428b8ed6ab414931ec7a78aceee.zip gcc-16e723e600a62428b8ed6ab414931ec7a78aceee.tar.gz gcc-16e723e600a62428b8ed6ab414931ec7a78aceee.tar.bz2 |
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
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 15 | ||||
-rw-r--r-- | gcc/cp/init.c | 4 | ||||
-rw-r--r-- | gcc/cp/parser.c | 9 | ||||
-rw-r--r-- | gcc/cp/pt.c | 20 |
5 files changed, 27 insertions, 28 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index cf738cb..066d293 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 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 6ca138d..9c4664c 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 15046b4..a17e160 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 1766ef4..465ab8f 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 d4ae76a..4cb8238 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 |