use the symbol database to look up base classes in CheckClass::noMemset check

This commit is contained in:
Robert Reif 2011-03-22 21:24:28 -04:00
parent d36ed9aff1
commit 468a983db1
2 changed files with 14 additions and 27 deletions

View File

@ -689,35 +689,19 @@ void CheckClass::unusedPrivateFunctionError(const Token *tok, const std::string
// ClassCheck: Check that memset is not used on classes // ClassCheck: Check that memset is not used on classes
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Token *typeTok) void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Scope *type)
{ {
// Warn if type is a class or struct that contains any std::* variables // recursively check all parent classes
const Scope *scope = symbolDatabase->findVariableType(start, typeTok); for (size_t i = 0; i < type->derivedFrom.size(); i++)
if (!scope)
return;
const Token *tstruct = scope->classDef;
const std::string &typeName = tstruct->str();
if (tstruct->tokAt(2)->str() == ":")
{ {
tstruct = tstruct->tokAt(3); if (type->derivedFrom[i].scope)
for (; tstruct; tstruct = tstruct->next()) checkMemsetType(start, tok, type->derivedFrom[i].scope);
{
while (Token::Match(tstruct, "public|private|protected|virtual"))
{
tstruct = tstruct->next();
}
// recursively check all parent classes
checkMemsetType(start, tok, tstruct);
tstruct = tstruct->next();
if (tstruct->str() != ",")
break;
}
} }
// Warn if type is a class or struct that contains any std::* variables
const Token *tstruct = type->classDef;
const std::string &typeName = tstruct->str();
for (; tstruct; tstruct = tstruct->next()) for (; tstruct; tstruct = tstruct->next())
{ {
if (tstruct->str() == "}") if (tstruct->str() == "}")
@ -823,7 +807,10 @@ void CheckClass::noMemset()
if (!typeTok) if (!typeTok)
continue; continue;
checkMemsetType(&(*scope), tok, typeTok); const Scope *type = symbolDatabase->findVariableType(&(*scope), typeTok);
if (type)
checkMemsetType(&(*scope), tok, type);
} }
} }
} }

View File

@ -84,7 +84,7 @@ public:
* Important: The checking doesn't work on simplified tokens list. * Important: The checking doesn't work on simplified tokens list.
*/ */
void noMemset(); void noMemset();
void checkMemsetType(const Scope *start, const Token *tok, const Token *typeTok); void checkMemsetType(const Scope *start, const Token *tok, const Scope *type);
/** @brief 'operator=' should return something and it should not be const. */ /** @brief 'operator=' should return something and it should not be const. */
void operatorEq(); void operatorEq();