Super Lint
Walter Bright
newshound at digitalmars.com
Wed Sep 20 14:11:11 PDT 2006
Ivan Senji wrote:
> Walter Bright wrote:
>> Pragma wrote:
>>> Walter Bright wrote:
>>>> I've been interested in various ideas for static checking for common
>>>> bug patterns for D. For example:
>>>>
>>>> for (int i = 0; i < 10; i++)
>>>> { foo();
>>>> break;
>>>> }
>>>>
>>>> would be flagged as a suspicious use of break.
> But is it safe do declare the above example as a bug? Maybe that break
> is placed there to see what just one pass of the loop does (maybe for
> debugging purposes).
That certainly is the question. I don't think I'd want to see such code
in released source, but:
1) is it legitimate for debug/test code?
2) can it come about as the side effect of some other coding pattern?
3) if it is made illegal, is that going to be a bigger problem than it
solves?
4) does it really solve a problem?
For example, it could happen with (example found on the internet):
for (int i = 0; i < 10; i++)
{
if (condition)
action();
break;
}
where the user forgot to put { } around the else clause. It's sort of
like how:
for (int i = 0; i < 10; i++);
{
...
}
is illegal in D (note the ; after the closing parenthesis). I've known
people to spend many hours trying to track down this nearly invisible bug.
More information about the Digitalmars-d
mailing list