[cfe-commits] [PATCH][PR11329] Generalize -Wempty-body: warn when statement body is a empty
Matthieu Monrocq
matthieu.monrocq at gmail.com
Wed Jan 4 12:22:54 PST 2012
Le 4 janvier 2012 20:44, Dmitri Gribenko <gribozavr at gmail.com> a écrit :
> On Wed, Jan 4, 2012 at 9:03 PM, Nico Weber <thakis at chromium.org> wrote:
> > I ran this patch on a chromium build. It finds many false positives,
> > [...] Since this pattern is apparently
> > often used intentionally I'm not sure if this is a useful warning in
> > practice.
>
> I'm afraid of this running into a coding style argument (with a
> compiler). Before we had -Wparenthethes in GCC people didn't write
> parentheses around assignments that are also used as boolean values
> and I'm sure some didn't like the noise they got when -Wparenthethes
> got implemented.
>
> I agree that we might want to reduce false positive rate for `for' and
> `while' statements, but more elaborate ways (for example, checking if
> the statement is followed by a CompoundStmt) would require shifting
> this to static analyzer.
>
> Dmitri
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
>
>
There is one potential issue with diagnosing empty blocks such as
for (int j : arr)
{
}
What if the original code looked like:
for (int j : arr)
{
assert(j >= 0 && j < 1024 && "Too big value!");
}
I do not know if it is possible to realize that there was a macro and it
just got "vaporized" during the preprocessing...
Unless your code acts *before* the preprocessor, in which case it seems
just fine :)
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).
-- Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120104/418b8508/attachment.html>
More information about the cfe-commits
mailing list