Re: [PATCH 4/24] gdb: replace some so_list parameters to use references

Simon Marchi
2023-10-19T16:07:24Z

On 10/19/23 11:20, Lancelot SIX wrote:
>
>>>> - void on_solib_loaded (so_list *so) override;
>>>> - void on_solib_unloaded (so_list *so) override;
>>>> + void on_solib_loaded (const so_list &so) override;
>>>> + void on_solib_unloaded (const so_list &so) override;
>>>
>>> It is orthogonal to this change, but it would make sense for those
>>> methods to be const as well.
>>>
>>> Doing this requires interp::interp_ui_out to be const as well (as done
>>> in attached patch).
>>
>> Why do you think the interp object should be const (which is the effect
>> of marking the methods const)? These methods are notifiers to let the
>> interp know about certain events that occured. Whether they should
>> modify the state of the interpreter or not is up to the particular
>> implementation of the interpreter. Perhaps you're right, but I don't
>> see it.
>>
>
> It is just that current interps (MI really) are just forwarding notifications. The event does not change the interp's state.
> Does it has to be const? No. But usually I tend to make things const unless there is a reason not to. That's all.

But if I make the method const for MI, I need to make it const for all
interps, including CLI and TUI, right? So then we need to extend the
reflection to whether it makes sense to make the method const for them
too (hence my question about the non-const ui_out behind a const cli
interp).

Simon