Fixed #928 (false positive: member variable not initialized in constructor)

This commit is contained in:
Daniel Marjamäki 2009-11-10 19:30:37 +01:00
parent b470ea06b8
commit c301dc1907
2 changed files with 12 additions and 3 deletions

View File

@ -130,8 +130,11 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses)
varname = next->strAt(3); varname = next->strAt(3);
} }
// Array?
else if (Token::Match(next, "%type% %var% [") && next->next()->str() != "operator") else if (Token::Match(next, "%type% %var% [") && next->next()->str() != "operator")
{ {
if (Token::findmatch(_tokenizer->tokens(), ("class " + next->str()).c_str()))
continue;
varname = next->strAt(1); varname = next->strAt(1);
} }

View File

@ -406,8 +406,8 @@ private:
"private:\n" "private:\n"
" char name[255];\n" " char name[255];\n"
"};\n"); "};\n");
ASSERT_EQUALS("[test.cpp:4]: (style) Member variable not initialized in the constructor 'John::name'\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (style) Member variable not initialized in the constructor 'John::name'\n", errout.str());
checkUninitVar("class John\n" checkUninitVar("class John\n"
"{\n" "{\n"
"public:\n" "public:\n"
@ -416,7 +416,6 @@ private:
"private:\n" "private:\n"
" char name[255];\n" " char name[255];\n"
"};\n"); "};\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar("class John\n" checkUninitVar("class John\n"
@ -427,7 +426,6 @@ private:
"private:\n" "private:\n"
" char name[255];\n" " char name[255];\n"
"};\n"); "};\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar("class John\n" checkUninitVar("class John\n"
@ -437,7 +435,15 @@ private:
"\n" "\n"
" double operator[](const unsigned long i);\n" " double operator[](const unsigned long i);\n"
"};\n"); "};\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("class A;\n"
"class John\n"
"{\n"
"public:\n"
" John() { }\n"
" A a[5];\n"
"};\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }