[Issue 21112] New: std.conv.to fails to convert to 'typedef' like enum
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Aug 4 18:23:36 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21112
Issue ID: 21112
Summary: std.conv.to fails to convert to 'typedef' like enum
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: schveiguy at yahoo.com
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.
--
More information about the Digitalmars-d-bugs
mailing list