This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Make dwarf_expr_piece::pieces an std::vector


On 2017-09-14 11:21, Pedro Alves wrote:
On 09/14/2017 09:15 AM, Simon Marchi wrote:

 static struct piece_closure *
 allocate_piece_closure (struct dwarf2_per_cu_data *per_cu,
-			int n_pieces, struct dwarf_expr_piece *pieces,
+			const std::vector<dwarf_expr_piece> &&pieces,

const rval reference looks odd -- you can't really move
the internal elements out of a const vector.  I think ...

 			struct frame_info *frame)
 {
-  struct piece_closure *c = XCNEW (struct piece_closure);
+  struct piece_closure *c = new piece_closure;
   int i;

   c->refc = 1;
   c->per_cu = per_cu;
-  c->n_pieces = n_pieces;
-  c->pieces = XCNEWVEC (struct dwarf_expr_piece, n_pieces);
+  c->pieces = std::move (pieces);

... this isn't really moving, but actually copying, because
you'll end up calling 'std::vector(const std::vector &)', not
'std::vector(std::vector &&)'.

I wonder if there's ever a case for 'const T &&' parameters,
and if GCC could warn about them.  At least in non-template
functions.

Oops, I started with a const reference, before changing it to rvalue reference (and forgot to remove the const). Does the patch look good to you otherwise?

Simon


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]