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

Andrew Burgess andrew.burgess@embecosm.com
Sun Aug 16 09:13:18 GMT 2020


* Tom Tromey <tom@tromey.com> [2020-08-15 11:16:46 -0600]:

> >>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
> 
> Andrew> The current enum bit flags mechanism provides global operators &, |,
> Andrew> ^, ~, but does not provide &=, |=, ^=.
> 
> Andrew> The implementation for one of these, |=, would look like this:
> 
> Andrew>   template <typename enum_type>
> Andrew>   typename enum_flags_type<enum_type>::type &
> Andrew>   operator|= (enum_type &e1, enum_type e2)
> 
> Why "enum_type &e1" and not "enum_flags_type<enum_type>::type &e1" here?
> 
> Andrew>   DEF_ENUM_FLAGS_TYPE(enum some_flag, some_flags);
> 
> Andrew>   enum some_flag f = flag_val1 | flag_val2;
> Andrew>   f |= flag_val3;
> 
> To me this example looks incorrect -- the idea behind enum flags is to
> not use the "enum some_flag" type, but instead the wrapper.  So it
> should be:
> 
>     some_flags f = flag_val1 | flag_val2;
>     f |= flag_val3;
> 
> Could you say why you want to use the enum type instead?  That would
> help me understand this patch.

Thanks for the feedback.  I believe that I was trying to make the
header work with existing code in GDB where 'enum' is used.

I'll double check this (I wrote this patch a long time ago now), but
if this is the case then, based on your comments, I suspect the
"correct" fix is to patch GDB to remove the use of 'enum' (in those
places where 'DEF_ENUM_FLAGS_TYPE' is used), and then add the extra
operators I need.

I'll update this patch and repost.

I don't think this should impact the rest of this series in any
significant way.

Thanks,
Andrew


More information about the Gdb-patches mailing list