Fixed #1584 (False positive: (static) Member variable not assigned a value in operator=)
This commit is contained in:
parent
38a28e28ec
commit
1328a57103
|
@ -554,13 +554,7 @@ void CheckClass::checkConstructors(const Token *tok1, const std::string &funcnam
|
||||||
// Check if any variables are uninitialized
|
// Check if any variables are uninitialized
|
||||||
for (Var *var = varlist; var; var = var->next)
|
for (Var *var = varlist; var; var = var->next)
|
||||||
{
|
{
|
||||||
if (var->init)
|
if (var->init || var->isStatic)
|
||||||
continue;
|
|
||||||
|
|
||||||
// Is it a static member variable?
|
|
||||||
std::ostringstream pattern;
|
|
||||||
pattern << className << " :: " << var->name << " =";
|
|
||||||
if (Token::findmatch(_tokenizer->tokens(), pattern.str().c_str()))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// It's non-static and it's not initialized => error
|
// It's non-static and it's not initialized => error
|
||||||
|
|
|
@ -48,6 +48,7 @@ private:
|
||||||
TEST_CASE(uninitVar2);
|
TEST_CASE(uninitVar2);
|
||||||
TEST_CASE(uninitVar3);
|
TEST_CASE(uninitVar3);
|
||||||
TEST_CASE(uninitVar4);
|
TEST_CASE(uninitVar4);
|
||||||
|
TEST_CASE(uninitVar5);
|
||||||
TEST_CASE(uninitVarEnum);
|
TEST_CASE(uninitVarEnum);
|
||||||
TEST_CASE(uninitVarStream);
|
TEST_CASE(uninitVarStream);
|
||||||
TEST_CASE(uninitVarTypedef);
|
TEST_CASE(uninitVarTypedef);
|
||||||
|
@ -1499,6 +1500,19 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uninitVar5()
|
||||||
|
{
|
||||||
|
checkUninitVar("class Foo\n"
|
||||||
|
"{\n"
|
||||||
|
"public:\n"
|
||||||
|
" Foo() { }\n"
|
||||||
|
" Foo &operator=(const Foo &)\n"
|
||||||
|
" { return *this; }\n"
|
||||||
|
" static int i;\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void uninitVarArray1()
|
void uninitVarArray1()
|
||||||
{
|
{
|
||||||
checkUninitVar("class John\n"
|
checkUninitVar("class John\n"
|
||||||
|
|
Loading…
Reference in New Issue