>
>
>
V790. It is suspicious that the assignm…


V790. It is suspicious that the assignment operator takes an object by a non-constant reference and returns this object.

The analyzer has detected an assignment operator that receives an object by a non-constant reference and returns that same object.

Consider the following example:

class C {
  C& operator = (C& other) {
    ....
    return other;
  }
};

Implementing an assignment operator in a way like that could lead to unexpected and unpleasant side effects. Suppose we write the following code:

(A = B)++;

You should not really write the code like that, but just suppose we need it exactly that way. You would probably expect the following sequence of operations:

A = B;
A++;

However, because of the incorrect assignment operator, the actual order will be this:

A = B;
B++;

To avoid errors like that, pass the argument by a constant reference: code with such an implementation of the assignment operator would simply fail to compile.

Fixed code:

class C {
  C& operator = (const C& other) {
    ....
    return *this;
  }
};