When I run cppcheck on the following code:
#include <cstring> #include <iconv.h> class IconvConversionDescriptor { public: IconvConversionDescriptor(const char* fromCode, const char* toCode); IconvConversionDescriptor(IconvConversionDescriptor& that); ~IconvConversionDescriptor(); private: iconv_t cd_; }; IconvConversionDescriptor::IconvConversionDescriptor(const char* fromCode, const char* toCode) : cd_(iconv_open(fromCode, toCode)) {} IconvConversionDescriptor::IconvConversionDescriptor(IconvConversionDescriptor& that) : cd_(that.cd_) { that.cd_ = (iconv_t)-1; } IconvConversionDescriptor::~IconvConversionDescriptor() { if (cd_ != (iconv_t)-1) iconv_close(cd_); }
I get the following performance warning:
$ cppcheck --enable=style --template=gcc iconvcvt.cpp iconvcvt.cpp:22:10: warning: Variable 'cd_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] that.cd_ = (iconv_t)-1; ^
But I am not assigning a value to this->cd_ but to that.cd_. I cannot move this assignment to the initialization list.
this->cd_
that.cd_
Seems like Cppcheck sees this incorrectly as an assignment to a member variable of the current object? Or am I missing something?
This is with Cppcheck 1.86 on CentOS 7.
Looks like this is a bug.
https://github.com/danmar/cppcheck/pull/2128
Log in to post a comment.
When I run cppcheck on the following code:
I get the following performance warning:
But I am not assigning a value to
this->cd_
but tothat.cd_
. I cannot move this assignment to the initialization list.Seems like Cppcheck sees this incorrectly as an assignment to a member variable of the current object? Or am I missing something?
This is with Cppcheck 1.86 on CentOS 7.
Looks like this is a bug.
https://github.com/danmar/cppcheck/pull/2128