V728. Excessive check can be simplified. The '||' operator is surrounded by opposite expressions 'x' and '!x'.
The analyzer has detected code that can be simplified. The left and right operands of the '||' operation are expressions with opposite meanings. This code is redundant and can be simplified by reducing the number of checks.
Here's an example of redundant code:
if (!Name || (Name && Name[0] == 0))
In the "Name && Name[0] == 0" expression, the 'Name' check is excessive because before it, the expression '!Name', which is opposite to it, is checked, these expressions being separated by the '||' operation. Consequently, the excessive check in the parentheses can be omitted to simplify the code:
if (!Name || Name[0] == 0)
Redundancy may indicate there is an error in the code: it might be that a wrong variable is used in the expression, so the correct version of the code should really look something like this:
if (!Foo || (Name && Name[0] == 0))
The analyzer outputs this warning not only for 'x' and '!x' constructs, but for other expressions with opposite meanings as well. For example:
if (a > 5 || (a <= 5 && b))
This diagnostic is classified as:
You can look at examples of errors detected by the V728 diagnostic. |