Share via


C6289

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

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