<div dir="ltr">Please, don't lock the attached file using Google Preview. Download it and open it with your favorite text editor.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Apr 21, 2014 at 12:04 PM, Fernando Pelliccioni <span dir="ltr"><<a href="mailto:fpelliccioni@gmail.com" target="_blank">fpelliccioni@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi all, </div><div><br></div><div>The following code snippet is related to the Apple bug of a few weeks ago.</div>
<div><br></div><div>void foo();</div><div>void bar();</div><div><br></div><div>void test( int a )</div>
<div>{</div><div><span style="white-space:pre-wrap"> </span>if ( a == 1 )</div><div><span style="white-space:pre-wrap"> </span>foo();</div><div><span style="white-space:pre-wrap"> </span>bar();</div><div>}</div>
<div><br></div><div>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.</div><div><br></div><div>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.</div>
<div><br></div><div><br></div><div>The following code is fine, no problem with it.</div><div>void test2()</div><div>{</div><div><span style="white-space:pre-wrap"> </span>foo();</div><div><span style="white-space:pre-wrap"> </span>bar();</div>
<div>}</div><div><br></div><div><br></div><div>I think the followings cases should be warned by the compiler.</div><div>void test3()</div><div>{</div><div><span style="white-space:pre-wrap"> </span>while (true) foo();</div>
<div><span style="white-space:pre-wrap"> </span>bar();</div><div>}</div><div><br></div><div>void test4()</div><div>{</div><div><span style="white-space:pre-wrap"> </span>if (true) foo();</div><div><span style="white-space:pre-wrap"> </span>bar();</div>
<div>}</div><div><br></div><div>To emphasize the problem I attached a source code file. Could you give it a quick look and tell me what is printed out? </div><div>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.</div>
<div><br></div><div><br></div><div>Do you think it would be useful to add these warnings to Clang?</div><div><br></div><div>Thanks and regards,</div><div>Fernando Pelliccioni.</div></div>
</blockquote></div><br></div>