Why PVS-Studio states that there is a non-constant reference?

28 Views Asked by At

I must first admit that I have very little experience with C++, so please forgive me if the question looks somewhat stupid.

I've found a puzzling element while analyzing project with PVS-Studio. Here's the code to reproduce the question:

class Test
{
public:
    const Test &Test::operator=(const Test &test);
};

const Test &Test::operator=(const Test &test) {
    if (this == &test)
        return test;

    return *this;
}

Of course, this assignment operator is unnecessary here, but the question is in the warning PVS-Studio generated on it:

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

(emphasis mine)

I'm not sure what to think. Where is this non-constant reference? Argument of the assignment operator is const Test &, i.e. it seems to be the constant reference. Furthermore, return test is executed only if the assignment is a no-op anyway, i.e. returning *this and test should make no difference.

Is this a false positive, or I simply don't understand something?

0

There are 0 best solutions below