Marcel Mueller
unread,Jun 26, 2016, 10:33:44 AM6/26/16You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
When I use enums with flags an define the type safe bit operators I get
warning in switch statements when I have bit combinations in a case
constant. (case value not in enumerated type)
Basically the overloaded operators cause the argument to switch to be of
the enum type rather than int. And now the compiler (here gcc) does some
consistency checks.
It is just a warning and I can turn it off, but this disables another
sometimes useful warning for other enum types that not all enum values
of the switch are handled.
Is there anything else I can do except for casting to int at the switch
statement?
enum Flags
{ None = 0
, Val1 = 1
, Val2 = 2
//...
};
inline constexpr Flags operator|(Flags l, Flags r)
{ return (Flags)((int)l|r); }
// further operators
int main()
{
Flags f = Val1|Val2;
switch (f)
{default:
return 0;
case Val1:
return 1;
case Val2:
return 2;
case Val1|Val2: // Warning!
return 3;
}
}