Fixed #1678 (false positive: Member variable not initialized in the constructor, for arrays of undefined type)
This commit is contained in:
parent
c0149d3cd1
commit
8e3c39ae5b
|
@ -152,9 +152,8 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo
|
|||
// Array?
|
||||
else if (Token::Match(next, "%type% %var% [") && next->next()->str() != "operator")
|
||||
{
|
||||
if (!withClasses)
|
||||
if (!withClasses && !next->isStandardType())
|
||||
{
|
||||
if (Token::findmatch(_tokenizer->tokens(), ("class|struct " + next->str()).c_str()))
|
||||
continue;
|
||||
}
|
||||
varname = next->strAt(1);
|
||||
|
@ -545,7 +544,7 @@ void CheckClass::checkConstructors(const Token *tok1, const std::string &funcnam
|
|||
const std::string className = tok1->strAt(1);
|
||||
|
||||
// Check that all member variables are initialized..
|
||||
bool withClasses = bool(_settings->inconclusive && funcname == "operator =");
|
||||
const bool withClasses = bool(_settings->inconclusive && funcname == "operator =");
|
||||
Var *varlist = getVarList(tok1, withClasses, isStruct);
|
||||
|
||||
int indentlevel = 0;
|
||||
|
|
|
@ -57,6 +57,7 @@ private:
|
|||
TEST_CASE(uninitVarArray2);
|
||||
TEST_CASE(uninitVarArray3);
|
||||
TEST_CASE(uninitVarArray4);
|
||||
TEST_CASE(uninitVarArray5);
|
||||
TEST_CASE(uninitVarArray2D);
|
||||
TEST_CASE(uninitMissingFuncDef);// can't expand function in constructor
|
||||
TEST_CASE(privateCtor1); // If constructor is private..
|
||||
|
@ -1627,6 +1628,19 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitVarArray5()
|
||||
{
|
||||
checkUninitVar("class Foo\n"
|
||||
"{\n"
|
||||
"private:\n"
|
||||
" Bar bars[10];\n"
|
||||
"public:\n"
|
||||
" Foo()\n"
|
||||
" { }\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitVarArray2D()
|
||||
{
|
||||
checkUninitVar("class John\n"
|
||||
|
|
Loading…
Reference in New Issue