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

Tom Tromey
2020-08-15T17:16:48Z

>>>>> "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.

Tom