Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Incorrect operator: mutual exclusion over
||
is always a non-zero constant. Did you intend to use&&
instead?
Remarks
This warning indicates that in a test expression a variable is being tested as unequal to two different constants. The result depends on either condition being true, but it always evaluates to true.
This problem is often caused by using ||
in place of &&
, but can also be caused by using !=
where ==
was intended.
Code analysis name: MUTUALEXCLUSIONOVERORISTRUE
Example
The following code generates this warning:
void f(int x)
{
if ((x != 1) || (x != 3))
{
// code
}
}
To correct this warning, use the following code:
void f(int x)
{
if ((x != 1) && (x != 3))
{
// code
}
}
/* or */
void f(int x)
{
if ((x == 1) || (x == 3))
{
// code
}
}