std.conv: conversion from ulong to enum

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Aug 22 21:14:36 PDT 2013


On Thu, Aug 22, 2013 at 06:54:45PM -0700, H. S. Teoh wrote:
> On Fri, Aug 23, 2013 at 03:37:11AM +0200, Andrej Mitrovic wrote:
> > On 8/23/13, H. S. Teoh <hsteoh at quickfur.ath.cx> wrote:
> > > Whether to() *should* attempt the conversion
> > > is a different matter, though.
> > 
> > to!() is used for save conversions, so it should try to convert and
> > throw an exception if conversion fails. For example:
> > 
> > byte x = to!byte(int.max);
> > 
> > std.conv.ConvOverflowException at conv.d(1335): Conversion positive overflow
> 
> Alright, opened a new bug for this:
> 
> 	http://d.puremagic.com/issues/show_bug.cgi?id=10874
[...]

And now it's fixed:

	https://github.com/D-Programming-Language/phobos/pull/1505

Turned out to be another signature constraint wrong-assumption bug.

Makes me wonder how many more such bugs lurk in Phobos. This isn't the
first time I've seen the signature constraints test for something, then
the code uses something else that doesn't necessarily follow from the
signature constraints. This is an especially inviting trap to fall into
when you have nice syntactic sugar like isIntegral or is(A : B); you
start reasoning in the abstract and overlook the concrete details, like
ulong not being implicitly convertible to int.


T

-- 
The best compiler is between your ears. -- Michael Abrash


More information about the Digitalmars-d mailing list