For the above example code, cppcheck 1.70 correctly reports the warning "[test1.cpp:22]: (warning) Member variable 'FooBar::bar' is not initialized in the constructor". However, if I replace the memset line FooBar constructor by:
memset(&this->foo, 0, sizeof(this->foo));
, cppcheck won't report the warning anymore. Look like it has issues with interpreting "this->" here.
Kind regards,
Cong-Van
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I couldn't log in into cppcheck.net (no verification email received), so just report the following bug here.
//------------------------------------------------------------------------------------------------------
include <iostream>
include <string.h>
typedef struct
{
int f;
} Foo;
typedef struct
{
int b;
} Bar;
class FooBar
{
public:
FooBar();
Foo foo;
Bar bar;
};
FooBar::FooBar()
{
memset(&foo, 0, sizeof(foo));
}
int main(void)
{
FooBar foobar;
std::cout << foobar.foo.f << foobar.bar.b << std::endl;
return 0;
}
For the above example code, cppcheck 1.70 correctly reports the warning "[test1.cpp:22]: (warning) Member variable 'FooBar::bar' is not initialized in the constructor". However, if I replace the memset line FooBar constructor by:
memset(&this->foo, 0, sizeof(this->foo));
, cppcheck won't report the warning anymore. Look like it has issues with interpreting "this->" here.
Kind regards,
Cong-Van
http://trac.cppcheck.net/ticket/7068