Share via


C6289

warning C6289: Incorrect operator: mutual exclusion over || is always a non-zero constant. Did you intend to use && instead?

This warning indicates that in a test expression a variable is being tested against two different constants and the result depends on either condition being true. This always evaluates to true.

This problem is generally caused by using || in place of &&, but can also be caused by using != where == was intended.

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 
  }
}