TestClass: Added test for uninitialized "mutable int i"
This commit is contained in:
parent
9b8571466c
commit
a9009ebf7d
|
@ -76,8 +76,14 @@ struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const Token *tok1)
|
||||||
const Token *next = tok->next();
|
const Token *next = tok->next();
|
||||||
const char *varname = 0;
|
const char *varname = 0;
|
||||||
|
|
||||||
|
// If next token contains a ":".. it is not part of a variable declaration
|
||||||
|
if (next->str().find(":") != std::string::npos)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Is it a variable declaration?
|
// Is it a variable declaration?
|
||||||
if (Token::Match(next, "%type% %var% ;"))
|
else if (Token::Match(next, "%type% %var% ;"))
|
||||||
{
|
{
|
||||||
if (next->isStandardType())
|
if (next->isStandardType())
|
||||||
varname = next->strAt(1);
|
varname = next->strAt(1);
|
||||||
|
@ -85,12 +91,28 @@ struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const Token *tok1)
|
||||||
varname = next->strAt(1);
|
varname = next->strAt(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Is it a variable declaration?
|
||||||
|
else if (Token::Match(next, "%type% %type% %var% ;"))
|
||||||
|
{
|
||||||
|
const Token *next2 = next->next();
|
||||||
|
if (next2->isStandardType())
|
||||||
|
varname = next2->strAt(1);
|
||||||
|
else if (Token::findmatch(_tokenizer->tokens(), ("enum " + next2->str()).c_str()))
|
||||||
|
varname = next2->strAt(1);
|
||||||
|
}
|
||||||
|
|
||||||
// Pointer?
|
// Pointer?
|
||||||
else if (Token::Match(next, "%type% * %var% ;"))
|
else if (Token::Match(next, "%type% * %var% ;"))
|
||||||
{
|
{
|
||||||
varname = next->strAt(2);
|
varname = next->strAt(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pointer?
|
||||||
|
else if (!b && Token::Match(next, "%type% %type% * %var% ;"))
|
||||||
|
{
|
||||||
|
varname = next->strAt(3);
|
||||||
|
}
|
||||||
|
|
||||||
// If the varname was set in one of the two if-block above, create a entry for this variable..
|
// If the varname was set in one of the two if-block above, create a entry for this variable..
|
||||||
if (varname)
|
if (varname)
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,6 +50,7 @@ private:
|
||||||
TEST_CASE(function); // Function is not variable
|
TEST_CASE(function); // Function is not variable
|
||||||
TEST_CASE(uninitVarHeader1); // Class is defined in header
|
TEST_CASE(uninitVarHeader1); // Class is defined in header
|
||||||
TEST_CASE(uninitVarHeader2); // Class is defined in header
|
TEST_CASE(uninitVarHeader2); // Class is defined in header
|
||||||
|
TEST_CASE(uninitVarHeader3); // Class is defined in header
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that base classes have virtual destructors
|
// Check that base classes have virtual destructors
|
||||||
|
@ -280,6 +281,20 @@ private:
|
||||||
ASSERT_EQUALS("[fred.h:6]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str());
|
ASSERT_EQUALS("[fred.h:6]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uninitVarHeader3()
|
||||||
|
{
|
||||||
|
checkUninitVar("#file \"fred.h\"\n"
|
||||||
|
"class Fred\n"
|
||||||
|
"{\n"
|
||||||
|
"private:\n"
|
||||||
|
" mutable int i;\n"
|
||||||
|
"public:\n"
|
||||||
|
" Fred() { }\n"
|
||||||
|
"};\n"
|
||||||
|
"#endfile\n");
|
||||||
|
ASSERT_EQUALS("[fred.h:6]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue