I have a class a header that looks something like this:
classMyClass{public:MyClass()=default;MyClass(constMyClass&)=default;MyClass(MyClass&&)=default;~MyClass()=default;MyClass&operator=(MyClasso){swap(o);return*this;}voidswap(MyClass&o)noexcept;private:std::unordered_map<int,std::string>theMap_{};// many other std::string member variables }
When I run cppcheck 1.81 on sources that include this header, it gives an operatorEqVarError error complaining that
"Member variable 'MyClass::theMap_' is not assigned a value in 'MyClass::operator='.
This is not surprising to me, as cppcheck doesn't see the definition of MyClass::swap(). What is surprising to me is that I actually have several classes that are defined like this, yet cppcheck only complains about this one.
Should cppcheck complain about this? If so, why doesn't it complain about this same construct in my other class headers? If not, why does it complaine here? Is there some way, short of making swap() inline, for cppcehck to know that swap() is in fact exchaning all the member variables?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a class a header that looks something like this:
When I run cppcheck 1.81 on sources that include this header, it gives an operatorEqVarError error complaining that
"Member variable 'MyClass::theMap_' is not assigned a value in 'MyClass::operator='.
This is not surprising to me, as cppcheck doesn't see the definition of MyClass::swap(). What is surprising to me is that I actually have several classes that are defined like this, yet cppcheck only complains about this one.
Should cppcheck complain about this? If so, why doesn't it complain about this same construct in my other class headers? If not, why does it complaine here? Is there some way, short of making swap() inline, for cppcehck to know that swap() is in fact exchaning all the member variables?
I get no repro with 2.3.