<div class="gmail_quote">On Mon, Jan 16, 2012 at 7:03 PM, Chad Rosier <span dir="ltr"><<a href="mailto:mcrosier@apple.com">mcrosier@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Nico,<br>
I get a warning with the following test case.<br>
<br>
int foo(int a, int b, int c) {<br>
int rval = 0;<br>
if (a != b)<br>
if (b == c) {<br>
rval = 0;<br>
} else {<br>
rval = 1;<br>
}<br>
return rval;<br>
}<br>
<br>
mcrosier$ clang -O3 t.c -Wall -c -o /dev/null<br>
t.c:6:11: warning: add explicit braces to avoid dangling else [-Wdangling-else]<br>
} else {<br>
^<br>
1 warning generated.<br>
<br>
Is this expected behavior? This code seems rather explicit to me.</blockquote><div><br></div><div>Yes, this was discussed and folks wanted the warning here as well.</div><div><br></div><div>This is no more explicit than:</div>
<div><br></div><div>if (foo)</div><div> if (bar)</div><div> ...;</div><div> else</div><div> ...;</div><div><br></div><div>The grammar indicates that the else (in both cases) attach to the inner if, but the {}s on the inner case don't actually make a difference.</div>
<div><br></div><div>I wasn't the biggest fan of these semantics, but they are at least consistent... </div></div>