[Issue 259] Comparing signed to unsigned does not generate an error
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Aug 30 13:49:00 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=259
--- Comment #63 from Dominikus Dittes Scherkl <dominikus at scherkl.de> ---
(In reply to Dominikus Dittes Scherkl from comment #58)
> So why don't we change to something that simply always works?
I have meanwhile improved my solution to something more straight forward, with
less superfluous casting, and now that the frontend is written in D, it should
be no problem to integrate it in the compiler:
int opCmp(T, U)(const(T) a, const(U) b) pure @safe @nogc nothrow
if(isIntegral!T && isIntegral!U && is(Unqual!T != Unqual!U))
{
static if(isSigned!T && isUnsigned!U && T.sizeof <= U.sizeof)
return (a < 0) ? -1 : opCmp(cast(U)a, b);
else static if(isUnsigned!T && isSigned!U && T.sizeof >= U.sizeof)
return (b < 0) ? 1 : opCmp(a, cast(T)b);
else // do interger propagation as ever:
return opCmp(cast(CommonType!(T, U))a, cast(CommonType!(T, U))b);
}
--
More information about the Digitalmars-d-bugs
mailing list