[PATCH 1/2] gdb: return *this in target_waitstatus setters

Pedro Alves pedro@palves.net
Fri Dec 3 13:10:36 GMT 2021


On 2021-12-02 01:40, Simon Marchi via Gdb-patches wrote:
> From: Simon Marchi <simon.marchi@efficios.com>
> 
> While playing with some code creating target_waitstatus objects, I was
> mildly annoyed by the fact that we can't just return a new
> target_waitstatus object.  We have to do:
> 
>     target_waitstatus ws;
>     ws.set_exited (123);
>     return ws;
> 
> Make the setters return the "this" object as a reference, such that it's
> possible to do:
> 
>     return target_waitstatus ().set_exited (123);
> 
> I initially thought of adding static creation functions, which you would
> use like:
> 
>     return target_waitstatus::make_exited (123);
> 
> However, making the setters return a reference to the object achieves
> pretty much the same thing, with less new code.

I think the static methods would be nicer (I'd maybe drop the "make_" to keep
it short), but I'm fine with this too, it doesn't seem mutually exclusive.

Series LGTM.


More information about the Gdb-patches mailing list