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

Argyrios Kyrtzidis kyrtzidis at apple.com
Mon Jan 16 10:29:02 PST 2012


On Jan 15, 2012, at 6:00 AM, Dmitri Gribenko wrote:

> On Wed, Jan 11, 2012 at 1:53 AM, Argyrios Kyrtzidis <kyrtzidis at apple.com> wrote:
>> On Jan 10, 2012, at 3:33 PM, Argyrios Kyrtzidis wrote:
>>> How about at least setting a flag to indicate if an empty while/for was encountered, and if not, skip the traversing of statements altogether ?
> 
> I think that we would need a stack of flags, or am I misunderstanding
> you?  For example:

Right, how about a stack of "CompoundScopeInfo"'s, part of FunctionScopeInfo, with only that flag as a member for starters ?
Also we'd probably need ActOnStartOfCompoundStmt / ActOnEndOfCompoundStmt Sema callbacks, called by Parser::ParseCompoundStatement, to push/pop CompoundScopeInfo.

> 
> void foo() {
> __for(...); // flag set
> ____a();
> __if(...) {
> ____while(...); // the same flag set
> ______b();
> __} // ActOnCompoundStatement checks the flag, checks statements,
> emits the warning about `while', clears flag
> } // ActOnCompoundStatement finds that flag is cleared => `for' warning is lost
> 
>>> And before setting the flag, check if the warning is disabled at that source location, which means no check is necessary at all.
> 
> This makes sense to me, but I couldn't find how to check (from Sema)
> if warning is enabled.  Could you give me a pointer?

Check uses of "Diags.getDiagnosticLevel()" in Sema, e.g. in Sema::CheckCompatibleReinterpretCast.

-Argyrios

> 
> Here's an improved version of the patch with helper methods moved to
> SemaChecking.cpp
> 
> 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>*/
> <generalize-warn-empty-body-v6.patch>_______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list