Bug 21112 – std.conv.to fails to convert to 'typedef' like enum

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-08-04T18:23:36Z
Last change time
2024-12-01T16:37:27Z
Assigned to
No Owner
Creator
Steven Schveighoffer
Moved to GitHub: phobos#10433 →

Comments

Comment #0 by schveiguy — 2020-08-04T18:23:36Z
A common use of enum is to create a new type wholly based on another type: enum foo : long; This can be used in all places a long would be used, but does not implicitly convert from a long. However, to cannot convert to such a type. In some cases we use this style of enum to define C types. For example: https://github.com/dlang/druntime/blob/0db2e65bba7cc319309bd32957763882870d5b03/src/core/stdc/config.d#L121 And therefore, this code fails: auto x = 1.0; auto y = x.to!(__c_ulonglong); std.conv.ConvException@/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2054): Value (1) does not match any member value of enum '__c_ulonglong' Either this should not compile, or it should cast. It should be detectable whether an enum has any members or not.
Comment #1 by robert.schadek — 2024-12-01T16:37:27Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10433 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB