Fixed #1584 (False positive: (static) Member variable not assigned a value in operator=)

This commit is contained in:
Daniel Marjamäki 2010-04-09 18:35:54 +02:00
parent 38a28e28ec
commit 1328a57103
2 changed files with 15 additions and 7 deletions

View File

@ -554,13 +554,7 @@ void CheckClass::checkConstructors(const Token *tok1, const std::string &funcnam
// Check if any variables are uninitialized
for (Var *var = varlist; var; var = var->next)
{
if (var->init)
continue;
// Is it a static member variable?
std::ostringstream pattern;
pattern << className << " :: " << var->name << " =";
if (Token::findmatch(_tokenizer->tokens(), pattern.str().c_str()))
if (var->init || var->isStatic)
continue;
// It's non-static and it's not initialized => error

View File

@ -48,6 +48,7 @@ private:
TEST_CASE(uninitVar2);
TEST_CASE(uninitVar3);
TEST_CASE(uninitVar4);
TEST_CASE(uninitVar5);
TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef);
@ -1499,6 +1500,19 @@ private:
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()
{
checkUninitVar("class John\n"