www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21112] New: std.conv.to fails to convert to 'typedef' like enum


          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 puremagic.com
          Reporter: schveiguy 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:


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.

Aug 04 2020