Symbol database: fixed false negative for uninitialized variable. ticket: #1895

This commit is contained in:
Robert Reif 2010-09-09 07:21:51 +02:00 committed by Daniel Marjamäki
parent 80be31de13
commit c3762903a9
2 changed files with 14 additions and 4 deletions

View File

@ -1020,10 +1020,7 @@ bool CheckClass::argsMatch(const Token *first, const Token *second, const std::s
// skip default value assignment
else if (first->next()->str() == "=")
{
first = first->tokAt(2);
continue;
}
// definition missing variable name
else if (first->next()->str() == "," && second->next()->str() != ",")
@ -1173,7 +1170,7 @@ void CheckClass::constructors()
if (classNameUsed)
operatorEqVarError(it->token, info->className, var->token->str());
}
else if (it->access != Private && !var->isStatic)
else if (it->access != Private)
uninitVarError(it->token, info->className, var->token->str());
}
}

View File

@ -54,6 +54,7 @@ private:
TEST_CASE(uninitVar8);
TEST_CASE(uninitVar9); // ticket #1730
TEST_CASE(uninitVar10); // ticket #1993
TEST_CASE(uninitVar11);
TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef);
@ -1645,6 +1646,18 @@ private:
ASSERT_EQUALS("[test.cpp:8]: (style) Member variable not initialized in the constructor 'A::var2'\n", errout.str());
}
void uninitVar11()
{
checkUninitVar("class A {\n"
"public:\n"
" A(int a = 0);\n"
"private:\n"
" int var;\n"
"};\n"
"A::A(int a) { }\n");
ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'A::var'\n", errout.str());
}
void uninitVarArray1()
{
checkUninitVar("class John\n"