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,34 +689,18 @@ void CheckClass::unusedPrivateFunctionError(const Token *tok, const std::string
// 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
const Scope *scope = symbolDatabase->findVariableType(start, typeTok);
if (!scope)
return;
const Token *tstruct = scope->classDef;
const std::string &typeName = tstruct->str();
if (tstruct->tokAt(2)->str() == ":")
{
tstruct = tstruct->tokAt(3);
for (; tstruct; tstruct = tstruct->next())
{
while (Token::Match(tstruct, "public|private|protected|virtual"))
{
tstruct = tstruct->next();
}
// recursively check all parent classes
checkMemsetType(start, tok, tstruct);
for (size_t i = 0; i < type->derivedFrom.size(); i++)
{
if (type->derivedFrom[i].scope)
checkMemsetType(start, tok, type->derivedFrom[i].scope);
}
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())
{
@ -823,7 +807,10 @@ void CheckClass::noMemset()
if (!typeTok)
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.
*/
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. */
void operatorEq();