>
>
>
V6041. Suspicious assignment inside the…


V6041. Suspicious assignment inside the conditional expression of 'if/while/do...while' statement.

The analyzer has detected an 'if'/ 'while'/'do...while' statement whose conditional expression contains the assignment operator '='. Such constructs often signal the presence of errors. The programmer probably intended to use the '==' operator rather than '='.

Consider the following example:

void func(int x, boolean skip, ...)
{
  if (skip = true) {
    return;
  }
  ...
  if ((x > 50) && (x < 150)) {
    ...
  }
  ...
}

This code has a typo in it: rather than checking the 'skip' variable, the programmer is changing its value. As a result, the condition will always be true and the 'return' statement will be executed all the time. Fixed code:

if (skip == true){
  return; 
}

or:

if (skip){
  return; 
}

This diagnostic is classified as: