diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index ff2a8a170..2845eee04 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -458,23 +458,18 @@ void CheckClass::initializeVarList(const Function &func, std::list } // Assignment of array item of member variable? - else if (Token::Match(ftok, "%var% [") && - Token::simpleMatch(ftok->next()->link(), "] =")) { - assignVar(ftok->str(), scope, usage); - } - - // Assignment of member of array item of member variable? - else if (Token::Match(ftok, "%var% [ ") && - (Token::Match(ftok->next()->link(), "] . %var% =") || - Token::Match(ftok->next()->link(), "] . %var% . %var% ="))) { - assignVar(ftok->str(), scope, usage); - } - - // Assignment of array item of member variable? - else if (Token::Match(ftok, "%var% [") && - Token::simpleMatch(ftok->next()->link(), "] [") && - Token::simpleMatch(ftok->next()->link()->next()->link(), "] =")) { - assignVar(ftok->str(), scope, usage); + else if (Token::Match(ftok, "%var% [|.")) { + const Token *tok2 = ftok; + while (tok2) { + if (Token::simpleMatch(tok2->next(), "[")) + tok2 = tok2->next()->link(); + else if (Token::Match(tok2->next(), ". %var%")) + tok2 = tok2->tokAt(2); + else + break; + } + if (Token::Match(tok2, "%any% =")) + assignVar(ftok->str(), scope, usage); } // Assignment of array item of member variable? @@ -482,11 +477,6 @@ void CheckClass::initializeVarList(const Function &func, std::list assignVar(ftok->next()->str(), scope, usage); } - // Assignment of struct member of member variable? - else if (Token::Match(ftok, "%var% . %any% =")) { - assignVar(ftok->str(), scope, usage); - } - // The functions 'clear' and 'Clear' are supposed to initialize variable. if (Token::Match(ftok, "%var% . clear|Clear (")) { assignVar(ftok->str(), scope, usage); diff --git a/test/testclass.cpp b/test/testclass.cpp index f68caad2d..002d57834 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -77,6 +77,7 @@ private: TEST_CASE(uninitVarArray6); TEST_CASE(uninitVarArray7); TEST_CASE(uninitVarArray2D); + TEST_CASE(uninitVarArray3D); TEST_CASE(uninitVarStruct1); // ticket #2172 TEST_CASE(uninitVarStruct2); // ticket #838 TEST_CASE(uninitMissingFuncDef); // can't expand function in constructor @@ -2433,6 +2434,17 @@ private: ASSERT_EQUALS("", errout.str()); } + void uninitVarArray3D() { + checkUninitVar("class John\n" + "{\n" + "private:\n" + " char a[2][2][2];\n" + "public:\n" + " John() { a[0][0][0] = 0; }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + void uninitVarStruct1() { // ticket #2172 checkUninitVar("class A\n" "{\n"