diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 402b9f734..218f22561 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4707,7 +4707,9 @@ void Tokenizer::removeRedundantAssignment() const Token * const end = tok->next()->link(); for (Token *tok2 = tok->next(); tok2 && tok2 != end; tok2 = tok2->next()) { - if (Token::Match(tok2, "[;{}] %type% * %var% ;") && tok2->strAt(1) != "return") + if (Token::Match(tok2, "class|struct %type% {")) + tok2 = tok2->tokAt(2)->link(); // skip local class or struct + else if (Token::Match(tok2, "[;{}] %type% * %var% ;") && tok2->strAt(1) != "return") { tok2 = tok2->tokAt(3); localvars.insert(tok2->varId()); diff --git a/test/testclass.cpp b/test/testclass.cpp index dbf91fecb..99d79262e 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -64,6 +64,7 @@ private: TEST_CASE(uninitVar17); TEST_CASE(uninitVar18); // ticket #2465 TEST_CASE(uninitVar19); // ticket #2792 + TEST_CASE(uninitVar20); // ticket #2867 TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarStream); TEST_CASE(uninitVarTypedef); @@ -2210,6 +2211,19 @@ private: ASSERT_EQUALS("", errout.str()); } + void uninitVar20() // ticket #2867 + { + checkUninitVar("Object::MemFunc() {\n" + " class LocalClass {\n" + " public:\n" + " LocalClass() : dataLength_(0) {}\n" + " std::streamsize dataLength_;\n" + " double bitsInData_;\n" + " } obj;\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor.\n", errout.str()); + } + void uninitVarArray1() { checkUninitVar("class John\n"