[cfe-dev] Usefull warnings

Fernando Pelliccioni fpelliccioni at gmail.com
Mon Apr 21 08:04:33 PDT 2014


Hi all,

The following code snippet is related to the Apple bug of a few weeks ago.

void foo();
void bar();

void test( int a )
{
if ( a == 1 )
foo();
bar();
}

The original source code of the Apple bug has Goto's instead of function
calls, but the problem is essentially the same, and it is related to
scoping.

I wonder if you considered convenient adding a warning if Clang detects
that a line is indented so that does not match the natural indentation of
its scope, especially there are a conditional around.


The following code is fine, no problem with it.
void test2()
{
foo();
bar();
}


I think the followings cases should be warned by the compiler.
void test3()
{
while (true) foo();
bar();
}

void test4()
{
if (true) foo();
bar();
}

To emphasize the problem I attached a source code file. Could you give it a
quick look and tell me what is printed out?
I know that it is an extreme and malicious example, but it help us to
understand that when we given a quick look to the code, we can ignore cases
like these.


Do you think it would be useful to add these warnings to Clang?

Thanks and regards,
Fernando Pelliccioni.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140421/89ae32ba/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: apple_bug_clang.cpp
Type: text/x-c++src
Size: 292 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140421/89ae32ba/attachment.cpp>


More information about the cfe-dev mailing list