From 8e3c39ae5b73eaac0e6f6f89770dbdb12794b08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=E4ki?= Date: Sat, 15 May 2010 20:24:11 +0200 Subject: [PATCH] Fixed #1678 (false positive: Member variable not initialized in the constructor, for arrays of undefined type) --- lib/checkclass.cpp | 7 +++---- test/testclass.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index a2814a5cc..8862ffa63 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -152,10 +152,9 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo // Array? else if (Token::Match(next, "%type% %var% [") && next->next()->str() != "operator") { - if (!withClasses) + if (!withClasses && !next->isStandardType()) { - if (Token::findmatch(_tokenizer->tokens(), ("class|struct " + next->str()).c_str())) - continue; + continue; } varname = next->strAt(1); } @@ -545,7 +544,7 @@ void CheckClass::checkConstructors(const Token *tok1, const std::string &funcnam const std::string className = tok1->strAt(1); // Check that all member variables are initialized.. - bool withClasses = bool(_settings->inconclusive && funcname == "operator ="); + const bool withClasses = bool(_settings->inconclusive && funcname == "operator ="); Var *varlist = getVarList(tok1, withClasses, isStruct); int indentlevel = 0; diff --git a/test/testclass.cpp b/test/testclass.cpp index a7fd3277b..d93c5d0a2 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -57,6 +57,7 @@ private: TEST_CASE(uninitVarArray2); TEST_CASE(uninitVarArray3); TEST_CASE(uninitVarArray4); + TEST_CASE(uninitVarArray5); TEST_CASE(uninitVarArray2D); TEST_CASE(uninitMissingFuncDef);// can't expand function in constructor TEST_CASE(privateCtor1); // If constructor is private.. @@ -1627,6 +1628,19 @@ private: ASSERT_EQUALS("", errout.str()); } + void uninitVarArray5() + { + checkUninitVar("class Foo\n" + "{\n" + "private:\n" + " Bar bars[10];\n" + "public:\n" + " Foo()\n" + " { }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + void uninitVarArray2D() { checkUninitVar("class John\n"