Don <[email protected]> wrote:
I think there might be some low-hanging fruit, though.
Supposed we distinguished enums containing AssignExpressions from those
which do not.
It seems clear to me that logical operations should always be permitted
on enums where every member of the enum has been explicitly assigned a
value.
enum Enum1 { A = 1, B = 2, C = 4 }
---> A|B makes sense.
But if there are no assign expressions at all:
enum Enum2 { A, B, C }
then I think that performing arithmetic on that enum is almost certainly
a bug.
I wonder, what if the default base type of an enum was simply 'enum', a
type not implicitly convertible to other types. If you want implicit
casts, specify the base type:
enum foo { A, B, C = B } // No base type, no conversions allowed.
enum bar : int { D, E, F = E } // An int in disguise. Allow conversions.
That seems to follow D's tenet that the unsafe should be more verbose.
--
Simen