From 0de47f709eb7198e542bbe54ed6078cb6e22e4e9 Mon Sep 17 00:00:00 2001 From: Harald Scheidl Date: Sun, 16 Oct 2016 22:21:33 +0200 Subject: [PATCH] Fixed #7755 (false positive: member variable is not initialized in the constructor) --- lib/checkclass.cpp | 2 +- test/testconstructors.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 1257f27d9..e2804f159 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -633,7 +633,7 @@ void CheckClass::initializeVarList(const Function &func, std::liststr() == "::") ftok = ftok->next(); int offsetToMember = 4; - if (ftok->tokAt(ftok->strAt(2) == "&")) + if (ftok->strAt(2) == "&") ++offsetToMember; assignVar(ftok->tokAt(offsetToMember)->varId(), scope, usage); ftok = ftok->linkAt(1); diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index c897e1c91..41889900a 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -2849,6 +2849,16 @@ private: " return foobar.foo.f + foobar.bar.b;\n" "}"); ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'FooBar::bar' is not initialized in the constructor.\n", errout.str()); + + // #7755 + check("struct A {\n" + " A() {\n" + " memset(this->data, 0, 42);\n" + " }\n" + " char data[42];\n" + "};"); + ASSERT_EQUALS("", errout.str()); + } void privateCtor1() {