Hi Chad,

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.

This was discussed when I proposed the warning:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20111219/050474.html

Richard and Eli both preferred the warning to fire in this case,
Chandler was against it.

I'm happy with adding any tweak we agree on (say "don't warn if the
else starts on the same line the previous if starts" or something like
that).

How often do you run into this in practice?

Nico

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to