Skip to content

Commit 0de47f7

Browse files
githubharalddanmar
authored andcommitted
Fixed cppcheck-opensource#7755 (false positive: member variable is not initialized in the constructor)
1 parent 4216b26 commit 0de47f7

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
633633
if (ftok->str() == "::")
634634
ftok = ftok->next();
635635
int offsetToMember = 4;
636-
if (ftok->tokAt(ftok->strAt(2) == "&"))
636+
if (ftok->strAt(2) == "&")
637637
++offsetToMember;
638638
assignVar(ftok->tokAt(offsetToMember)->varId(), scope, usage);
639639
ftok = ftok->linkAt(1);

test/testconstructors.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,6 +2849,16 @@ class TestConstructors : public TestFixture {
28492849
" return foobar.foo.f + foobar.bar.b;\n"
28502850
"}");
28512851
ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'FooBar::bar' is not initialized in the constructor.\n", errout.str());
2852+
2853+
// #7755
2854+
check("struct A {\n"
2855+
" A() {\n"
2856+
" memset(this->data, 0, 42);\n"
2857+
" }\n"
2858+
" char data[42];\n"
2859+
"};");
2860+
ASSERT_EQUALS("", errout.str());
2861+
28522862
}
28532863

28542864
void privateCtor1() {

0 commit comments

Comments
 (0)