D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23492 - Enum types with float base don't match the spec
Summary: Enum types with float base don't match the spec
Status: RESOLVED DUPLICATE of issue 18578
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-17 11:05 UTC by Ate Eskola
Modified: 2023-01-30 17:02 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ate Eskola 2022-11-17 11:05:54 UTC
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.
Comment 1 Nick Treleaven 2023-01-30 17:02:28 UTC

*** This issue has been marked as a duplicate of issue 18578 ***