[cfe-commits] [PATCH][PR11329][v4] Generalize -Wempty-body: warn when statement body is empty

Dmitri Gribenko gribozavr at gmail.com
Tue Jan 10 15:11:29 PST 2012


Hello Nico,

Thanks for testing!

On Wed, Jan 11, 2012 at 12:34 AM, Nico Weber <thakis at chromium.org> wrote:
> I ran a build of chromium and dependencies again, and that resulted in
> 3 false positives (2 in libxml, 1 in hunspell – in addition to 1 in
> sqlite that already exists with the old warning).

They all follow a pattern:
<TAB>for(...);
<8 spaces>statement;
Thus, `for' starts at column 2, `statement' starts at column 9 and
because it has more indentation it is suspected to be for's body.  If
they would start at the same column, it would be considered a false
positive and no warning would be emitted (this is the heuristic what
removed most warnings in chrome).

> 1.) Maybe the "note" text could be tweaked to suggest that using
> braces is fine, and that adding a space in front of the ';' is
> sufficient too?

Spaces before `;' don't matter (line number of statement and semicolon
matters for loops).

> 2.) It would be nice if -Wempty-body for if statements would also
> print this new note – it looks like it's only printed for loops at the
> moment.

Moving `;' on a new line doesn't silence the warning for `if', because
`if(...);' doesn't make sense.  `if(...) assert(...);' preprocesses to
`if(...) (void) 0;', so this idiom is not affected.

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>*/




More information about the cfe-commits mailing list