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

Dmitri Gribenko gribozavr at gmail.com
Wed Jan 4 08:47:43 PST 2012


Hello,

Attached is a patch that implements enhancement proposed in PR11329.

Differences from the StaticAnalyzer patch I posted yesterday:
* implemented as a warning
* also warn when range-based for has an empty CompoundStmt body:
for (int j : arr)
{
}
I think this case shouldn't add too much noise in real programs
(compared to clang testsuite) because setting up a foreach-style
iteration and doing nothing in the body can only be meaningful if
begin(), end() etc expressions that are automagically generated by
compiler contain side-effects.

I didn't merge existing tests for `if statement has empty body' with
my new tests.

Commit message:
Generalize -Wempty-body to warn about empty body in for, range-based
for, while and switch statements.

Best regards,
Dmitri Gribenko

-- 
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.patch
Type: text/x-diff
Size: 28686 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120104/41d2c9d1/attachment.patch>


More information about the cfe-commits mailing list