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