Super Lint
Kevin Bealer
kevinbealer at gmail.com
Sat Sep 23 01:29:50 PDT 2006
Frits van Bommel wrote:
> Walter Bright wrote:
>> xs0 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. Are there any
>>>> legitimate uses of break in this manner? Any thoughts and ideas in
>>>> this direction?
>>>
>>> Well, I occasionally write something similar:
>>>
>>> for (int i = 0; i < max_retries; i++) {
>>> try {
>>> foo();
>>> } catch (Exception e) {
>>> continue;
>>> }
>>> break;
>>> }
>>
>> Hmm. That does look like a quite reasonable use case.
>
> It also looks like a quite /detectable/ use case. Just look for a
> continue statement somewhere in that loop (and outside any nested ones).
Couldn't this be simplified to:
for(...) {
try {
foo();
break;
} catch(...)
}
}
Though I guess this doesn't necessarily mean the first form is
lint-error-worthy.
Kevin
More information about the Digitalmars-d
mailing list