C6287
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 C6287.
warning C6287: redundant code: the left and right sub-expressions are identical
This warning indicates that a redundant element was detected in an expression.
It is difficult to judge the severity of this problem without examining the code. A duplicate test on its own is harmless, but the consequences of deleting the second test can be severe. The code should be inspected to ensure that a test was not omitted.
The following code generates this warning:
void f(int x)
{
if ((x == 1) && (x == 1))
{
//logic
}
if ((x != 1) || (x != 1))
{
//logic
}
}
The following code shows various methods to correct this warning:
void f(int x, int y)
{
/* Remove the redundant sub-expression: */
if (x == 1)
{
// logic
}
if (x != 1)
{
// logic
}
/* or test the missing variable: */
if ((x == 1) && (y == 1))
{
// logic
}
if ((x != 1) || (y != 1))
{
// logic
}
}
Show: