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

Anna Zaks ganna at apple.com
Tue Jan 10 10:57:00 PST 2012


Hi Dmitri,

I think you should move the calls to diagnose the empty for and while loop statements out of ActOnCompoundStmt into the ActOnWhileStmt and ActOnForStmt. Then, you would only perform the check to see if the following statement is on the same line if the body is actually empty. This would make code cleaner as well.

Here is one way to implement it (suggestion by Argyrios). You can store a member variable inside Sema to flag if potential warning is diagnosed. When processing the next statement in ActOnExprStmt, you can check the identation and make the final decision.

Minor issues:

Factor the check for empty loop body into a separate function.

Indentation is off in several places (I saw this in at least 3 places):
+  if (QuietIfBodyOnSeparateLine)
+  {
=>
+  if (QuietIfBodyOnSeparateLine)  {

Missing space here: if(BodyCol > StmtCol) 

Thanks,
Anna.

On Jan 7, 2012, at 3:05 PM, Dmitri Gribenko wrote:

> On Thu, Jan 5, 2012 at 9:22 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
>> Attached is a patch that implements enhancement proposed in PR11329.
> 
> *ping*
> 
> Are there any issues with this patch?  Any other cases to include/exclude?
> 
> 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>*/
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120110/6abadff9/attachment.html>


More information about the cfe-commits mailing list