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.
apple_bug_clang.cpp (292 Bytes)