versat - 2020-10-28

Hi,

i have found code like the following in a project and get a warning by Cppcheck which i do not know is correct.
The code is like this simplified version:

#include <utility>

class Base
{
    public:
    int m_Base = 0;
    Base() = default;
    virtual ~Base() = default;
};

class Derived : public Base
{
    public:
    int m_Foo = 0;
    Derived() : Base() {};
    Derived& operator=(Derived&& src)
    {
        if (&src != this)
        {
            Base::operator=(std::move(src));
            m_Foo = src.m_Foo;
        }
        return *this;
    }
};

For the line 21 where it says m_Foo = src.m_Foo; the online Cppcheck demo prints this warning:

Cppcheck 2.2
[test.cpp:21]: (warning, inconclusive) Access of moved variable 'src'.
Done!

It is marked inconclusive, so i am extra unsure if this code is correct or not.
Intuitively i would say Cppcheck could be right and calling the Base class move assignment operator should be moved after the other access of src.
I have found somewhat related but not perfectly matching stackoverflow questions, so i hope you experts here know more about it. I also appreciate any hint where i could read about such a case :)