How do I disable "Add explicit braces to avoid dangling else" in new xCode? How do I disable "Add explicit braces to avoid dangling else" in new xCode? xcode xcode

How do I disable "Add explicit braces to avoid dangling else" in new xCode?


This worked for me:

#ifdef __llvm__#pragma GCC diagnostic ignored "-Wdangling-else"#endif


Its not a bug. Apple LLVM warns you in cases where you have a nested if-else if-else block. Look at the code below:

if (Condition1)    if (Condition2)        return Statement2;    else if (Condition3)        Statement3;    else        Statement4;

By looking at the above code, its confusing for the parser to understand to which 'if' the 'else' is connected with? Remember that its not mandatory to have a else for every else-if, so it can be very likely that the else statement might be linked to the if (Condition1) rather than if (Condition2).

Apple llvm Compiler is smart enough to not make this folly but warns the user to reconsider the code to make sure that the user didn't want it the other way.

Generally the warning can be resolved by adding braces to the all the top level if statements. In the example above, the warning would go away by adding braces to if (Condition1). Check the more readable (warning less) code below:

if (Condition1){    if (Condition2)        return Statement2;    else if (Condition3)        Statement3;    else        Statement4;}


OK --- there's an option under Apple LLVM compiler 4.0 - Warnings called

Missing Braces and Parentheses

Setting that to NO gets rid of this warning.

Unfortunately, there doesn't seem to be a way to JUST get rid of the braces warning.

Apple, you're starting to impose too much on how I develop. Stop!