Fixed #1993 (False negatives: uninitialised variables in constructor)

This commit is contained in:
Robert Reif 2010-08-29 16:36:10 +02:00 committed by Daniel Marjamäki
parent 54e313efdc
commit a862e982ff
2 changed files with 16 additions and 1 deletions

View File

@ -242,7 +242,8 @@ void CheckClass::createSymbolDatabase()
while (found->next()->str() != "(")
found = found->next();
if (Token::Match(found->next()->link(), function.isConst ? ") const {" : ") {"))
if (Token::Match(found->next()->link(), function.isConst ? ") const {" : ") {") ||
(function.type == Func::Constructor && Token::Match(found->next()->link(), ") :|{")))
{
if (argsMatch(funcArgs, found->tokAt(2), classPath, depth))
{

View File

@ -53,6 +53,7 @@ private:
TEST_CASE(uninitVar7);
TEST_CASE(uninitVar8);
TEST_CASE(uninitVar9); // ticket #1730
TEST_CASE(uninitVar10); // ticket #1993
TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef);
@ -1628,6 +1629,19 @@ private:
ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Prefs::xasd'\n", errout.str());
}
void uninitVar10() // ticket #1993
{
checkUninitVar("class A {\n"
"public:\n"
" A();\n"
"private:\n"
" int var1;\n"
" int var2;\n"
"};\n"
"A::A() : var1(0) { }\n");
ASSERT_EQUALS("[test.cpp:8]: (style) Member variable not initialized in the constructor 'A::var2'\n", errout.str());
}
void uninitVarArray1()
{
checkUninitVar("class John\n"