diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index a909b427c..9601f868d 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1614,6 +1614,13 @@ void SymbolDatabase::SpaceInfo::initializeVarList(const Func &func, std::liststr()); } + // Assignment of member of array item of member variable? + else if (Token::Match(ftok, "%var% [ %any% ] . %var% =") || + Token::Match(ftok, "%var% [ %any% ] . %var% . %var% =")) + { + assignVar(ftok->str()); + } + // Assignment of array item of member variable? else if (Token::Match(ftok, "%var% [ %any% ] [ %any% ] =")) { diff --git a/test/testclass.cpp b/test/testclass.cpp index edcbd97c4..685930b46 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -60,6 +60,7 @@ private: TEST_CASE(uninitVar14); // ticket #2149 TEST_CASE(uninitVar15); TEST_CASE(uninitVar16); + TEST_CASE(uninitVar17); TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarStream); TEST_CASE(uninitVarTypedef); @@ -1987,6 +1988,38 @@ private: ASSERT_EQUALS("[test.cpp:10]: (warning) Member variable not initialized in the constructor 'Bar::foo'\n", errout.str()); } + void uninitVar17() + { + checkUninitVar("struct Foo\n" + "{\n" + " int a;\n" + "};\n" + "class Bar\n" + "{\n" + " Foo foo[10];\n" + "public:\n" + " Bar()\n" + " {\n" + " foo[0].a = 0;\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + + checkUninitVar("struct Foo\n" + "{\n" + " int a;\n" + "};\n" + "class Bar\n" + "{\n" + " Foo foo[10];\n" + "public:\n" + " Bar()\n" + " {\n" + " }\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable not initialized in the constructor 'Bar::foo'\n", errout.str()); + } + void uninitVarArray1() { checkUninitVar("class John\n"