diff options
author | Patrick Palka <ppalka@redhat.com> | 2021-11-11 08:10:20 -0500 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2021-11-11 08:10:20 -0500 |
commit | e106221db2eee30641b856db68858f1131c0fcf5 (patch) | |
tree | 2f33aed16c2a30adfc1be5ee74913c48490990fb /gcc/cp/parser.c | |
parent | fa4fcb111ad4ef015c1caf7c4b5a60d35b3aa997 (diff) | |
download | gcc-e106221db2eee30641b856db68858f1131c0fcf5.zip gcc-e106221db2eee30641b856db68858f1131c0fcf5.tar.gz gcc-e106221db2eee30641b856db68858f1131c0fcf5.tar.bz2 |
c++: use auto_vec in cp_parser_template_argument_list
gcc/cp/ChangeLog:
* parser.c (cp_parser_template_argument_list): Use auto_vec
instead of manual memory management.
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r-- | gcc/cp/parser.c | 35 |
1 files changed, 8 insertions, 27 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 4c1fed0..adfd3c1 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -18558,11 +18558,6 @@ cp_parser_template_name (cp_parser* parser, static tree cp_parser_template_argument_list (cp_parser* parser) { - tree fixed_args[10]; - unsigned n_args = 0; - unsigned alloced = 10; - tree *arg_ary = fixed_args; - tree vec; bool saved_in_template_argument_list_p; bool saved_ice_p; bool saved_non_ice_p; @@ -18581,16 +18576,15 @@ cp_parser_template_argument_list (cp_parser* parser) parser->non_integral_constant_expression_p = false; /* Parse the arguments. */ + auto_vec<tree, 10> args; do { - tree argument; - - if (n_args) + if (!args.is_empty ()) /* Consume the comma. */ cp_lexer_consume_token (parser->lexer); /* Parse the template-argument. */ - argument = cp_parser_template_argument (parser); + tree argument = cp_parser_template_argument (parser); /* If the next token is an ellipsis, we're expanding a template argument pack. */ @@ -18610,29 +18604,16 @@ cp_parser_template_argument_list (cp_parser* parser) argument = make_pack_expansion (argument); } - if (n_args == alloced) - { - alloced *= 2; - - if (arg_ary == fixed_args) - { - arg_ary = XNEWVEC (tree, alloced); - memcpy (arg_ary, fixed_args, sizeof (tree) * n_args); - } - else - arg_ary = XRESIZEVEC (tree, arg_ary, alloced); - } - arg_ary[n_args++] = argument; + args.safe_push (argument); } while (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)); - vec = make_tree_vec (n_args); + int n_args = args.length (); + tree vec = make_tree_vec (n_args); - while (n_args--) - TREE_VEC_ELT (vec, n_args) = arg_ary[n_args]; + for (int i = 0; i < n_args; i++) + TREE_VEC_ELT (vec, i) = args[i]; - if (arg_ary != fixed_args) - free (arg_ary); parser->non_integral_constant_expression_p = saved_non_ice_p; parser->integral_constant_expression_p = saved_ice_p; parser->in_template_argument_list_p = saved_in_template_argument_list_p; |