Edit

Share via


Warning C6287

Redundant code: the left and right subexpressions are identical

Remarks

This warning is emitted when an expression contains redundant logic. The warning can indicate a logic error. For example, accidentally using the wrong variable. It might also be a redundant test that can be removed. Inspect the code to verify that there's no logic error.

Code analysis name: REDUNDANTTEST

Example

The following code generates this warning:

void f(int x, int y)
{
  // comparing against x twice is suspicious, should the second comparison use y?
  if ((x == 1) && (x == 1))
  {
    //...
  }
}

The following code shows various ways to correct this warning:

void f(int x, int y)
{
  // Fixed the second comparison to use y
  if ((x == 1) && (y == 1))
  {
     // ...
  }
  
  // If the second comparison was unnecessary it could be removed
  if (x == 1)
  {
     // ...
  }
}