www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23492] New: Enum types with float base don't match the spec


          Issue ID: 23492
           Summary: Enum types with float base don't match the spec
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: Ajieskola gmail.com

With dmd version 2.100.1,

rdmd --eval 'enum E : float{x, y} writeln(cast(float)E.x, " ", cast(float)E.y)'

prints "0, 1".

However, the spec states (17.2) that if a first member of enum type is not
specified, it should be the .init value of the base type. Thus this example
should print "nan nan".

Side note: the spec also states that if an unspecified member is equal to the
member before it, the compiler should error. Technically that part is not
violated by printing "nan nan" though because NaNs are not equal to themselves.
The compiler does not currently error if the first member is explicitly set as
nan so it behaves according to spec in that regard.

Nov 17 2022