EXP-dangling-else
In this section:
Synopsis
An else branch might be connected to an unexpected if statement.
Enabled by default
Yes
Severity/Certainty
Medium/High

Full description
An else branch might be connected to an unexpected if statement. An else branch is always connected with the closest possible if statement, but this might not always be the intention of the programmer. By explicitly putting braces around if statements where there might be ambiguity, you make the code more readable and your intentions clearer.
Coding standards
- CWE 483
Incorrect Block Delimitation
Code examples
The following code example fails the check and will give a warning:
void foo(int x, int y){
if (x < y)
if (x == 1)
++y;
else
++x;
}
The following code example passes the check and will not give a warning about this issue:
void foo(int x, int y){
if (x < y){
if (x == 1)
++y;
}
else
++x;
}