diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 90577eb2a..c53178a8d 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -283,6 +283,9 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va break; } + if (Token::Match(ftok->next(), "%var% . %var% (")) + ftok = ftok->tokAt(2); + if (!Token::Match(ftok->next(), "%var%") && !Token::Match(ftok->next(), "this . %var%") && !Token::Match(ftok->next(), "* %var% =") && diff --git a/test/testclass.cpp b/test/testclass.cpp index f979576c1..6da705fd6 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -50,6 +50,7 @@ private: TEST_CASE(uninitVar4); TEST_CASE(uninitVar5); TEST_CASE(uninitVar6); + TEST_CASE(uninitVar7); TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarStream); TEST_CASE(uninitVarTypedef); @@ -1538,6 +1539,28 @@ private: ASSERT_EQUALS("", errout.str()); } + void uninitVar7() + { + checkUninitVar("class Foo {\n" + " int a;\n" + "public:\n" + " Foo() : a(0) {}\n" + " Foo& operator=(const Foo&);\n" + " void Swap(Foo& rhs);\n" + "};\n" + "\n" + "void Foo::Swap(Foo& rhs) {\n" + " std::swap(a,rhs.a);\n" + "}\n" + "\n" + "Foo& Foo::operator=(const Foo& rhs) {\n" + " Foo copy(rhs);\n" + " copy.Swap(*this);\n" + " return *this;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void uninitVarArray1() { checkUninitVar("class John\n"