Range of enum type values

Johan Engelen j at j.nl
Sat Dec 28 20:34:35 UTC 2019


On Saturday, 28 December 2019 at 20:20:46 UTC, Walter Bright 
wrote:
> I am skeptical about the value of major breaking changes with 
> enums at this point, as it doesn't seem like there are a lot of 
> undetected bugs emanating from the fairly loose definition of 
> them.

Yeah, I agree. It's good to clarify things in the spec though. To 
prevent someone (i.e. me) from trying to use enum range 
information for optimization.

https://github.com/dlang/dlang.org/pull/2728

Can we add a text like: "The enum type can be used in operator 
expressions (like AddExpression): the resulting type is the enum 
type, and the resulting value is computed by performing the 
operation as if the type is the enum base type. A variable of 
type enum does not have to have a value that corresponds with any 
of the enum members; the range of valid values for an enum typed 
variable is [basetype.min ... basetype.max]."

I'm not so satisfied with this text though.

-Johan



More information about the Digitalmars-d mailing list