Re: [PATCH 1/8] gdbsupport: Provide global operators |=, &=, and ^= for enum bit flags

Andrew Burgess
2020-08-21T15:57:44Z

* Pedro Alves <pedro@palves.net> [2020-08-21 15:49:15 +0100]:

> On 8/17/20 11:40 AM, Andrew Burgess wrote:
>
> >
> > 3. Instead of writing 'enum some_flag', a developer might just write
> > 'some_flag'.
>
> I suspect you meant 'some_flags' in the latter case.

No, I meant 'some_flag'.

>
> > In this case they still require the changes from my
> > patch if they ever want to use operator|=. I think spotting the
> > missing 's' is much harder during review,
>
> I'd argue that that's an issue of naming. If people thing it's a
> problem, we can use a more distinct name for the raw enums.
> Some cases use enum foo_flag_value / foo_flags, which seems reasonable
> to me.

I don't understand where 'enum foo_flag_value' came from, so I can't
really respond to this.

>
> > so it's easy for uses of
> > 'some_flag' to creep into the code base, then a future developer
> > wanting to use 'operator|=' will need to fix up the 'some_flag' to
> > 'some_flags' miss-match. Though it's easy to argue that the first
> > developer made a mistake, and we frequently have to fix the mistakes
> > of those going before, in this case we don't have to, so why force
> > the matter?
> >
> > I guess my argument would be, lets commit. We should either remove
> > the existing global operators from enum-flags.h, fix up the fall out,
> > and so make it much harder to developers to use the 'some_flag'
> > version (so forcing the use of 'some_flags'), or make the change I
> > propose which allows the full range of operators while loosing non of
> > the protection that already exists.
>
> This (again) reminded me of my enum-flags.h rewrite that I never
> managed to commit...
>
> I spent time around it yesterday/today, and posted it here:
> https://sourceware.org/pipermail/gdb-patches/2020-August/171392.html

I saw this. Once this gets merged I'll rebase the rest of my series
on top of your work, at which point I assume that this patch will not
be required.

Thanks for your help,

Andrew

>
> Thanks,
> Pedro Alves