Description: "uint i = -1" is allowed by dmd 1.050.
Expectation: A warning or an error should be shown by compiling the code.
I misspelled int as uint. A boolean expression (if i < 0) always equals false. It took me long time to debug my code. Finally I have found out, that the value i is not -1.
Comment #1 by bugzilla — 2009-11-02T16:08:08Z
I'll put this as an enhancement request because negate is currently an operation that is defined to work on unsigned values, hence no error.
Comment #2 by pro.mathias.lang — 2015-11-22T12:23:45Z
This 'bug' is still around in D2.
It looks like an heritage from C / C++, one of the bad kind.
It allows you to write gems such as:
```
uint func (int i) { return i; }
void main ()
{
uint v = func(-42);
}
```
@Walter: Would you be okay with the idea of deprecating this ?
Related: https://issues.dlang.org/show_bug.cgi?id=259
Comment #3 by dmitry.olsh — 2018-05-16T09:05:21Z
That would make unsigned types way more sane to work with.
And those who like -1 to be shortcut for "all 1's" could use ~0.
Comment #4 by robert.schadek — 2024-12-13T17:50:50Z