std.conv.ConvException from double to uint64_t, but only locally in a large project
schveiguy at gmail.com
Tue Aug 4 18:15:01 UTC 2020
On 8/4/20 1:36 PM, drathier wrote:
> I'm getting a crash when I'm converting a double to an uint64_t.
> Value (1596) does not match any member value of enum '__c_ulonglong'
> I've narrowed down the code to this:
> static import std.conv;
> double thing = 42.0;
> which works just fine on https://run.dlang.io/ or in a single-file dmd
> invocation. When I compile and run it locally on my mac as part of a
> specific large app using dub, it always crashes like this.
> Where would I even start debugging this?
> DMD64 D Compiler v2.093.0
> DUB version 1.22.0, built on Jul 9 2020
So a common way to typedef something is to use enum:
enum uint64_t : ulong;
This gives you a new type that works pretty much just like ulong, but
will not implicitly convert from ulong.
However, std.conv.to is likely interpreting this as an enumeration type,
where it has to match one of the enum members. But since this isn't an
enumeration in the standard way, it fails (it has no members!)
This code reproduces the problem on run.dlang.io:
auto x = 0.5;
auto y = x.to!__c_ulonglong;
Note the code in druntime which defines __c_ulonglong:
I'll file a bug.
More information about the Digitalmars-d-learn