Warning 1539 for smart pointer reset in assignment operator

Post a reply


This question is a means of preventing automated form submissions by spambots.

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is OFF
Smilies are OFF

Topic review
   

Expand view Topic review: Warning 1539 for smart pointer reset in assignment operator

Warning 1539 for smart pointer reset in assignment operator

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

Hi,

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
{
    public:
    std::unique_ptr<int> m_ptrInt1;
    
    const Foo& Foo::operator=(const Foo& otherFoo)
    {
        if (this != &otherFoo)
        {
            m_ptrInt1.reset(otherFoo.m_ptrInt1.get());
        }
        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?

Thanks,
Sebastian

Top