Page 1 of 1

Warning 1539 for smart pointer reset in assignment operator

Posted: Tue Oct 13, 2020 7:00 am
by Sebastian

i wonder why we get Warning 1539 in an assignment operator for smart pointers that are reset.
I have stripped the code down to a simplified demo that triggers the warning in the online demo:

Code: Select all

#include <memory>

class Foo
    std::unique_ptr<int> m_ptrInt1;
    const Foo& Foo::operator=(const Foo& otherFoo)
        if (this != &otherFoo)
        return *this;

int main()
    Foo f1;
    Foo f2;
    f2 = f1;
    return 0;
The exact warning is:

Code: Select all

warning 1539: member 'Foo::m_ptrInt1' not assigned by assignment operator 'Foo::operator='
The warning is also triggered when a new object, copied from the parameter object, is assigned via reset. So it looks like reset() is not handled at all in that situation.
IMHO it looks like a false positive. If so, would you fix it and how can i best suppress the warning?