diff options
author | Tom Tromey <tom@tromey.com> | 2024-02-03 14:32:06 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2024-02-04 15:37:55 -0700 |
commit | b36a26343a6c62b313d9e101b369155b6b799535 (patch) | |
tree | c5a73b5832f4ccbb914626230e2aeac11db0ab59 | |
parent | 029e52bac7f3a6dd8b39f7f3d298b73174da806b (diff) | |
download | gdb-b36a26343a6c62b313d9e101b369155b6b799535.zip gdb-b36a26343a6c62b313d9e101b369155b6b799535.tar.gz gdb-b36a26343a6c62b313d9e101b369155b6b799535.tar.bz2 |
Use reference result of emplace_back
Starting with C++17, emplace_back returns a reference to the new
object. This patch changes code that uses emplace_back followed by a
call to back() to simply use this reference instead.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
-rw-r--r-- | gdb/ada-lex.l | 4 | ||||
-rw-r--r-- | gdb/btrace.c | 4 | ||||
-rw-r--r-- | gdb/buildsym.c | 6 | ||||
-rw-r--r-- | gdb/dwarf2/expr.c | 3 | ||||
-rw-r--r-- | gdb/dwarf2/read.c | 30 | ||||
-rw-r--r-- | gdb/macroexp.c | 7 | ||||
-rw-r--r-- | gdb/remote.c | 3 | ||||
-rw-r--r-- | gdb/reverse.c | 3 | ||||
-rw-r--r-- | gdb/tracepoint.c | 3 | ||||
-rw-r--r-- | gdb/ui-out.c | 11 | ||||
-rw-r--r-- | gdb/windows-nat.c | 3 | ||||
-rw-r--r-- | gdb/xcoffread.c | 3 |
12 files changed, 25 insertions, 55 deletions
diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l index bb43673..828ff9a 100644 --- a/gdb/ada-lex.l +++ b/gdb/ada-lex.l @@ -462,8 +462,8 @@ processInt (struct parser_state *par_state, const char *base0, return FLOAT; } - int_storage.emplace_back (new gdb_mpz (std::move (result))); - const gdb_mpz *value = int_storage.back ().get (); + const gdb_mpz *value + = int_storage.emplace_back (new gdb_mpz (std::move (result))).get (); int int_bits = gdbarch_int_bit (par_state->gdbarch ()); int long_bits = gdbarch_long_bit (par_state->gdbarch ()); diff --git a/gdb/btrace.c b/gdb/btrace.c index a2aaa20..b5a047b 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -255,8 +255,8 @@ ftrace_new_function (struct btrace_thread_info *btinfo, insn_offset = prev->insn_offset + ftrace_call_num_insn (prev); } - btinfo->functions.emplace_back (mfun, fun, number, insn_offset, level); - return &btinfo->functions.back (); + return &btinfo->functions.emplace_back (mfun, fun, number, insn_offset, + level); } /* Update the UP field of a function segment. */ diff --git a/gdb/buildsym.c b/gdb/buildsym.c index a963219..5061109 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -661,8 +661,7 @@ buildsym_compunit::record_line (struct subfile *subfile, int line, return; } - subfile->line_vector_entries.emplace_back (); - linetable_entry &e = subfile->line_vector_entries.back (); + linetable_entry &e = subfile->line_vector_entries.emplace_back (); e.line = line; e.is_stmt = (flags & LEF_IS_STMT) != 0; e.set_unrelocated_pc (pc); @@ -1134,8 +1133,7 @@ buildsym_compunit::augment_type_symtab () struct context_stack * buildsym_compunit::push_context (int desc, CORE_ADDR valu) { - m_context_stack.emplace_back (); - struct context_stack *newobj = &m_context_stack.back (); + struct context_stack *newobj = &m_context_stack.emplace_back (); newobj->depth = desc; newobj->locals = m_local_symbols; diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 01a4f53..9cfae10 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -1200,8 +1200,7 @@ dwarf_expr_context::stack_empty_p () const void dwarf_expr_context::add_piece (ULONGEST size, ULONGEST offset) { - this->m_pieces.emplace_back (); - dwarf_expr_piece &p = this->m_pieces.back (); + dwarf_expr_piece &p = this->m_pieces.emplace_back (); p.location = this->m_location; p.size = size; diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index e873d9c..eab56ec 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -11552,15 +11552,9 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die, const char *fieldname = ""; if (die->tag == DW_TAG_inheritance) - { - fip->baseclasses.emplace_back (); - new_field = &fip->baseclasses.back (); - } + new_field = &fip->baseclasses.emplace_back (); else - { - fip->fields.emplace_back (); - new_field = &fip->fields.back (); - } + new_field = &fip->fields.emplace_back (); new_field->offset = die->sect_off; @@ -12071,16 +12065,14 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, /* Create a new fnfieldlist if necessary. */ if (flp == nullptr) { - fip->fnfieldlists.emplace_back (); - flp = &fip->fnfieldlists.back (); + flp = &fip->fnfieldlists.emplace_back (); flp->name = fieldname; i = fip->fnfieldlists.size () - 1; } /* Create a new member function field and add it to the vector of fnfieldlists. */ - flp->fnfields.emplace_back (); - fnp = &flp->fnfields.back (); + fnp = &flp->fnfields.emplace_back (); /* Delay processing of the physname until later. */ if (cu->lang () == language_cplus) @@ -12681,10 +12673,7 @@ handle_variant_part (struct die_info *die, struct type *type, { variant_part_builder *new_part; if (fi->current_variant_part == nullptr) - { - fi->variant_parts.emplace_back (); - new_part = &fi->variant_parts.back (); - } + new_part = &fi->variant_parts.emplace_back (); else if (!fi->current_variant_part->processing_variant) { complaint (_("nested DW_TAG_variant_part seen " @@ -12696,8 +12685,7 @@ handle_variant_part (struct die_info *die, struct type *type, else { variant_field ¤t = fi->current_variant_part->variants.back (); - current.variant_parts.emplace_back (); - new_part = ¤t.variant_parts.back (); + new_part = ¤t.variant_parts.emplace_back (); } /* When we recurse, we want callees to add to this new variant @@ -12761,8 +12749,7 @@ handle_variant (struct die_info *die, struct type *type, = make_scoped_restore (&fi->current_variant_part->processing_variant, true); - fi->current_variant_part->variants.emplace_back (); - variant_field &variant = fi->current_variant_part->variants.back (); + variant_field &variant = fi->current_variant_part->variants.emplace_back (); variant.first_field = fi->fields.size (); /* In a variant we want to get the discriminant and also add a @@ -13157,8 +13144,7 @@ update_enumeration_type_from_children (struct die_info *die, flag_enum = 0; } - fields.emplace_back (); - struct field &field = fields.back (); + struct field &field = fields.emplace_back (); field.set_name (dwarf2_physname (name, child_die, cu)); field.set_loc_enumval (value); } diff --git a/gdb/macroexp.c b/gdb/macroexp.c index 9523550..b8a9b29 100644 --- a/gdb/macroexp.c +++ b/gdb/macroexp.c @@ -789,12 +789,10 @@ gather_arguments (const char *name, shared_macro_buffer *src, int nargs, for (;;) { - shared_macro_buffer *arg; int depth; /* Initialize the next argument. */ - args.emplace_back (); - arg = &args.back (); + shared_macro_buffer *arg = &args.emplace_back (); set_token (arg, src->text, src->text); /* Gather the argument's tokens. */ @@ -819,8 +817,7 @@ gather_arguments (const char *name, shared_macro_buffer *src, int nargs, missing. Add an empty argument in this case. */ if (nargs != -1 && args.size () == nargs - 1) { - args.emplace_back (); - arg = &args.back (); + arg = &args.emplace_back (); set_token (arg, src->text, src->text); } diff --git a/gdb/remote.c b/gdb/remote.c index 72f14e2..f775484 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -4027,8 +4027,7 @@ start_thread (struct gdb_xml_parser *parser, char *id = (char *) xml_find_attribute (attributes, "id")->value.get (); ptid_t ptid = read_ptid (id, NULL); - data->items.emplace_back (ptid); - thread_item &item = data->items.back (); + thread_item &item = data->items.emplace_back (ptid); attr = xml_find_attribute (attributes, "core"); if (attr != NULL) diff --git a/gdb/reverse.c b/gdb/reverse.c index 035623a..9a01163 100644 --- a/gdb/reverse.c +++ b/gdb/reverse.c @@ -123,8 +123,7 @@ save_bookmark_command (const char *args, int from_tty) error (_("target_get_bookmark failed.")); /* Set up a bookmark struct. */ - all_bookmarks.emplace_back (); - bookmark &b = all_bookmarks.back (); + bookmark &b = all_bookmarks.emplace_back (); b.number = ++bookmark_count; b.pc = regcache_read_pc (regcache); b.sal = find_pc_line (b.pc, 0); diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index abe8d2b..7005ca8 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -253,8 +253,7 @@ set_traceframe_context (frame_info_ptr trace_frame) struct trace_state_variable * create_trace_state_variable (const char *name) { - tvariables.emplace_back (name, next_tsv_number++); - return &tvariables.back (); + return &tvariables.emplace_back (name, next_tsv_number++); } /* Look for a trace state variable of the given name. */ diff --git a/gdb/ui-out.c b/gdb/ui-out.c index 23f4ce0..a5f1ba5 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -905,10 +905,7 @@ buffer_group::write (const char *buf, long length_buf, ui_file *stream) && m_buffered_output.back ().m_msg.back () != '\n') m_buffered_output.back ().m_msg.append (msg); else - { - m_buffered_output.emplace_back (msg); - m_buffered_output.back ().m_stream = stream; - } + m_buffered_output.emplace_back (msg).m_stream = stream; prev = cur + 1; } } @@ -918,8 +915,7 @@ buffer_group::write (const char *buf, long length_buf, ui_file *stream) void buffer_group::wrap_here (int indent, ui_file *stream) { - m_buffered_output.emplace_back ("", indent); - m_buffered_output.back ().m_stream = stream; + m_buffered_output.emplace_back ("", indent).m_stream = stream; } /* See ui-out.h. */ @@ -927,8 +923,7 @@ buffer_group::wrap_here (int indent, ui_file *stream) void buffer_group::flush_here (ui_file *stream) { - m_buffered_output.emplace_back ("", -1, true); - m_buffered_output.back ().m_stream = stream; + m_buffered_output.emplace_back ("", -1, true).m_stream = stream; } /* See ui-out.h. */ diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 6fdd1f3..48b0d10 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -887,8 +887,7 @@ windows_make_so (const char *name, LPVOID load_addr) } } #endif - windows_process.solibs.emplace_back (); - windows_solib *so = &windows_process.solibs.back (); + windows_solib *so = &windows_process.solibs.emplace_back (); so->load_addr = load_addr; so->original_name = name; #ifndef __CYGWIN__ diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 589208c..e324f4e 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -428,8 +428,7 @@ arrange_linetable (std::vector<linetable_entry> &old_linetable) if (old_linetable[ii].line == 0) { /* Function entry found. */ - fentries.emplace_back (); - linetable_entry &e = fentries.back (); + linetable_entry &e = fentries.emplace_back (); e.line = ii; e.is_stmt = true; e.set_unrelocated_pc (old_linetable[ii].unrelocated_pc ()); |