On Mon, Jan 16, 2012 at 7:03 PM, Chad Rosier <[email protected]> wrote:

> Hi Nico,
> I get a warning with the following test case.
>
> int foo(int a, int b, int c) {
>    int rval = 0;
>    if (a != b)
>        if (b == c) {
>            rval = 0;
>        } else {
>            rval = 1;
>        }
>    return rval;
> }
>
> mcrosier$ clang -O3 t.c -Wall -c -o /dev/null
> t.c:6:11: warning: add explicit braces to avoid dangling else
> [-Wdangling-else]
>        } else {
>          ^
> 1 warning generated.
>
> Is this expected behavior?  This code seems rather explicit to me.


Yes, this was discussed and folks wanted the warning here as well.

This is no more explicit than:

if (foo)
  if (bar)
    ...;
  else
    ...;

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.

I wasn't the biggest fan of these semantics, but they are at least
consistent...
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to