Symbol database: reduce false negatives for 'uninitialized variable' when calling base class function. ticket: #1895
This commit is contained in:
parent
84d9282da2
commit
6de1711515
|
@ -806,6 +806,33 @@ void CheckClass::SpaceInfo::clearAllVar()
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool CheckClass::SpaceInfo::isBaseClassFunc(const Token *tok)
|
||||||
|
{
|
||||||
|
// Iterate through each base class...
|
||||||
|
for (unsigned int i = 0; i < derivedFrom.size(); ++i)
|
||||||
|
{
|
||||||
|
const SpaceInfo *info = derivedFrom[i].spaceInfo;
|
||||||
|
|
||||||
|
// Check if base class exists in database
|
||||||
|
if (info)
|
||||||
|
{
|
||||||
|
std::list<Func>::const_iterator it;
|
||||||
|
|
||||||
|
for (it = info->functionList.begin(); it != info->functionList.end(); ++it)
|
||||||
|
{
|
||||||
|
if (it->tokenDef->str() == tok->str())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Base class not found so assume it is in it.
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void CheckClass::SpaceInfo::initializeVarList(const Func &func, std::list<std::string> &callstack)
|
void CheckClass::SpaceInfo::initializeVarList(const Func &func, std::list<std::string> &callstack)
|
||||||
{
|
{
|
||||||
bool Assign = false;
|
bool Assign = false;
|
||||||
|
@ -964,7 +991,7 @@ void CheckClass::SpaceInfo::initializeVarList(const Func &func, std::list<std::s
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// could be a base class virtual function, so we assume it initializes everything
|
// could be a base class virtual function, so we assume it initializes everything
|
||||||
if (!derivedFrom.empty())
|
if (isBaseClassFunc(ftok))
|
||||||
assignAllVar();
|
assignAllVar();
|
||||||
|
|
||||||
// has friends, so we assume it initializes everything
|
// has friends, so we assume it initializes everything
|
||||||
|
|
|
@ -295,6 +295,8 @@ private:
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isBaseClassFunc(const Token *tok);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief Information about all namespaces/classes/structrues */
|
/** @brief Information about all namespaces/classes/structrues */
|
||||||
|
|
|
@ -1879,6 +1879,18 @@ private:
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str());
|
||||||
|
|
||||||
|
// Unknown non-member function
|
||||||
|
checkUninitVar("class ABC { };\n"
|
||||||
|
"class Fred : private ABC\n"
|
||||||
|
"{\n"
|
||||||
|
"public:\n"
|
||||||
|
" Fred() { Init(); }\n"
|
||||||
|
"private:\n"
|
||||||
|
" int i;\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:5]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitVarEnum()
|
void uninitVarEnum()
|
||||||
|
|
Loading…
Reference in New Issue