[Issue 259] Comparing signed to unsigned does not generate an error
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Apr 7 19:29:05 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=259
--- Comment #38 from bearophile_hugs at eml.cc 2013-04-07 19:29:00 PDT ---
(In reply to comment #35)
> 3. Otherwise, the comparison is in error. The error message may recommend using
> the std.traits.unsigned function, which executes a size-informed cast.
This is the source of unsigned:
auto unsigned(T)(T x) if (isIntegral!T)
{
static if (is(Unqual!T == byte )) return cast(ubyte ) x;
else static if (is(Unqual!T == short)) return cast(ushort) x;
else static if (is(Unqual!T == int )) return cast(uint ) x;
else static if (is(Unqual!T == long )) return cast(ulong ) x;
else
{
static assert(T.min == 0, "Bug in either unsigned or isIntegral");
return cast(Unqual!T) x;
}
}
Is it better to use template constraints there?
And isn't it better for unsigned to accept only unsigned Ts?
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list