<br><br><div class="gmail_quote">Le 4 janvier 2012 20:44, Dmitri Gribenko <span dir="ltr"><<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>></span> a écrit :<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Wed, Jan 4, 2012 at 9:03 PM, Nico Weber <<a href="mailto:thakis@chromium.org">thakis@chromium.org</a>> wrote:<br>
</div><div class="im">> I ran this patch on a chromium build. It finds many false positives,<br>
</div>> [...] Since this pattern is apparently<br>
<div class="im">> often used intentionally I'm not sure if this is a useful warning in<br>
> practice.<br>
<br>
</div>I'm afraid of this running into a coding style argument (with a<br>
compiler). Before we had -Wparenthethes in GCC people didn't write<br>
parentheses around assignments that are also used as boolean values<br>
and I'm sure some didn't like the noise they got when -Wparenthethes<br>
got implemented.<br>
<br>
I agree that we might want to reduce false positive rate for `for' and<br>
`while' statements, but more elaborate ways (for example, checking if<br>
the statement is followed by a CompoundStmt) would require shifting<br>
this to static analyzer.<br>
<font color="#888888"><br>
Dmitri<br>
</font><div class="im"><br>
--<br>
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>>*/<br>
</div><div><div></div><br></div></blockquote></div><br>There is one potential issue with diagnosing empty blocks such as<br><br><div style="margin-left:40px">for (int j : arr)<br>
{<br>
}<br></div><br>What if the original code looked like:<br><br><div style="margin-left:40px">for (int j : arr)<br>
{<br> assert(j >= 0 && j < 1024 && "Too big value!");<br>
}<br></div><br>I do not know if it is possible to realize that there was a macro and it just got "vaporized" during the preprocessing...<br><br>Unless your code acts *before* the preprocessor, in which case it seems just fine :)<br>
<br><br>On the other hand, as I replied to another of your email, I have personally seen occurrences of while( ... ) {} to explicitly state empty bodies and of course those should not warn I think (in non range-based for cases).<br>
<br>-- Matthieu<br>