[cfe-commits] [PATCH][PR11329][v4] Generalize -Wempty-body: warn when statement body is empty
Dmitri Gribenko
gribozavr at gmail.com
Thu Jan 5 11:22:45 PST 2012
Hello,
Attached is a patch that implements enhancement proposed in PR11329.
Thanks to the reviewers' comments, I've implemented the following
heuristic. For and while with null statement as a body should be
followed by a CompoundStmt in order to emit a warning.
But applying only the heuristic explained above limits the warning to
for(...);{...} cases. The second proposed heuristic is to emit a
warning also if for/while have less indentation than the next
statement, e. g.:
for (int i = 0; i < n; i++)
a(i);
Applying only the first heuristic silences all warnings in chromium.
Applying the second adds false positives in the following cases:
<TAB>for (...);
<8 spaces>foo();
and:
<INDENT>for (...);
<empty lines or comments...>
<MORE INDENT for some reason>foo();
We can silence the second case if we check that foo(); is on the next line.
All in all:
+ 3 warnings in chromium
+ 1 warning in llvm (can be silenced as explained above)
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>*/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: generalize-warn-empty-body-v4.patch
Type: text/x-diff
Size: 18942 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120105/5d3887a4/attachment.patch>
More information about the cfe-commits
mailing list