Potential low hanging fruit from PVS-Studio
Andrej Mitrovic
andrej.mitrovich at gmail.com
Wed Oct 19 12:01:50 PDT 2011
http://www.viva64.com/en/b/0113/
linked from: http://www.reddit.com/r/programming/comments/lhfji/static_analyzer_found_errors_in_chrome_again/
There was this kind of code:
void main()
{
int x = -1;
x =- 2;
assert(x == -3); // fail
}
This was apparently a typo in the Chrome source code. Perhaps the
compiler could detect this and emit a warning or stop compilation. To
work around it, you would have to add a space immediately after the
equals token if the next token is a minus or plus token. E.g.:
void main()
{
int x = -1;
x =-2; // ng
x =- 2; // ng
x = -2; // ok
x = - 2; // ok
x =+2; // ng
x =+ 2; // ng
x = +2; // ok
x = + 2; // ok
}
Alternatively a simple warning could be emitted.
However I don't know if this is a common enough bug to worry about, or
if it could potentially hurt metaprogramming.
More information about the Digitalmars-d
mailing list