The analyzer has detected duplicate conditions in an if and else if statements' chain. The code in the repeated condition will never execute, which indicates an error.
The example:
if (a == 1) {
foo();
} else if (a == 2) {
bar();
} else if (a == 1) {
baz();
}
In this example, the call to baz() is unreachable, since control flow never reaches it. This is probably a logic error, and the fixed code should look like this:
if (a == 1) {
foo();
} else if (a == 2) {
bar();
} else if (a == 3) {
baz();
}
Non-identical but equivalent expressions are also taken into account. The example:
if (a & b) {
foo();
} else if (b & a) {
bar();
}
This code triggers a warning because a bitwise AND is commutative, so the result will be the same.
This diagnostic rule is classified as:
Was this page helpful?
Your message has been sent. We will email you at
If you do not see the email in your inbox, please check if it is filtered to one of the following folders: