C6289
Visual Studio 2015
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at 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.
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
}
}
Show: