diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index d2fb2e3e4..48ea26ee9 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -409,6 +409,12 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va initVar(varlist, ftok->strAt(1)); } + // Assignment of struct member of member variable? + else if (Token::Match(ftok, "%var% . %any% =")) + { + initVar(varlist, ftok->strAt(0)); + } + // The functions 'clear' and 'Clear' are supposed to initialize variable. if (Token::Match(ftok, "%var% . clear|Clear (")) { diff --git a/test/testclass.cpp b/test/testclass.cpp index 14a48e8e3..4fb29ddb7 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -47,6 +47,7 @@ private: TEST_CASE(uninitVar1); TEST_CASE(uninitVar2); TEST_CASE(uninitVar3); + TEST_CASE(uninitVar4); TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarStream); TEST_CASE(uninitVarTypedef); @@ -1160,6 +1161,21 @@ private: ASSERT_EQUALS("", errout.str()); } + void uninitVar4() + { + checkUninitVar("class Foo\n" + "{\n" + "public:\n" + " Foo() { bar.x = 0; }\n" + "private:\n" + " struct Bar {\n" + " int x;\n" + " };\n" + " struct Bar bar;\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + void uninitVarArray1() { checkUninitVar("class John\n"