[Issue 6949] no warning or error if unsigned variable is compared to 0
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Nov 30 09:37:00 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6949
--- Comment #16 from bearophile_hugs at eml.cc 2012-11-30 09:36:58 PST ---
(In reply to comment #15)
> BTW std.bigint has a lot of examples of valid comparisons of unsigned < 0 .
The comparisons in std.bigint are like this, all of them are inside templated
functions:
BigInt opAssign(T: long)(T x)
{
data = cast(ulong)((x < 0) ? -x : x);
sign = (x < 0);
return this;
}
BigInt opOpAssign(string op, T)(T y)
if ((op=="+" || op=="-" || op=="*" || op=="/" || op=="%"
|| op==">>" || op=="<<" || op=="^^") && is (T: long))
{
ulong u = cast(ulong)(y < 0 ? -y : y);
...
> It's easy.
> DSymbol.inTemplateInstance() returns non-NULL if you are inside a template.
> You just need to call it on the function you're in.
Thank you Don.
If it's not hard to do then I suggest to add that in this line to exclude
templates from this test, and take a look at what the Phobos autotester says:
// Error when unsigned type is compared less-than to zero, but not in enum
declarations or in static if
if ((!(sc->flags & SCOPEstaticif)) && sc->parent &&
!sc->parent->isEnumDeclaration())
--
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