convert remainder of CheckClass::noMemset to use symbol database

This commit is contained in:
Robert Reif 2011-03-22 22:23:57 -04:00
parent b05c192b56
commit 5314cc02b2
1 changed files with 21 additions and 49 deletions

View File

@ -698,62 +698,34 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
checkMemsetType(start, tok, type->derivedFrom[i].scope); checkMemsetType(start, tok, type->derivedFrom[i].scope);
} }
// Warn if type is a class or struct that contains any std::* variables // Warn if type is a class that contains any virtual functions
const Token *tstruct = type->classDef; std::list<Function>::const_iterator func;
const std::string &typeName = tstruct->str();
for (; tstruct; tstruct = tstruct->next()) for (func = type->functionList.begin(); func != type->functionList.end(); ++func)
{ {
if (tstruct->str() == "}") if (func->isVirtual)
break; memsetError(tok, tok->str(), "virtual method", type->classDef->str());
}
// struct with function? skip function body.. // Warn if type is a class or struct that contains any std::* variables
if (Token::simpleMatch(tstruct, ") {")) std::list<Variable>::const_iterator var;
for (var = type->varlist.begin(); var != type->varlist.end(); ++var)
{
// don't warn if variable static or const
if (!var->isStatic() && !var->isConst())
{ {
tstruct = tstruct->next()->link(); const Token *tok1 = var->typeStartToken();
if (!tstruct)
break;
}
// before a statement there must be either: // skip mutable token
// * private:|protected:|public: if (var->isMutable())
// * { } ; tok1 = tok1->next();
if (Token::Match(tstruct, "[;{}]") ||
tstruct->str().find(":") != std::string::npos)
{
if (Token::Match(tstruct->next(), "std :: %type% %var% ;"))
memsetError(tok, tok->str(), "'std::" + tstruct->strAt(3) + "'", typeName);
else if (Token::Match(tstruct->next(), "std :: %type% <")) // check for std:: type that is not a pointer or reference
{ if (Token::simpleMatch(tok1, "std ::") && !Token::Match(var->nameToken(), "*|&"))
// backup the type memsetError(tok, tok->str(), "'std::" + tok1->strAt(2) + "'", type->classDef->str());
const std::string typestr(tstruct->strAt(3));
// check if it's a pointer variable.. /** @todo warn if type is class/struct that doesn't require initialization */
unsigned int level = 0;
while (0 != (tstruct = tstruct->next()))
{
if (tstruct->str() == "<")
++level;
else if (tstruct->str() == ">")
{
if (level <= 1)
break;
--level;
}
else if (tstruct->str() == "(")
tstruct = tstruct->link();
}
if (!tstruct)
break;
// found error => report
if (Token::Match(tstruct, "> %var% ;"))
memsetError(tok, tok->str(), "'std::" + typestr + "'", typeName);
}
else if (Token::simpleMatch(tstruct->next(), "virtual"))
memsetError(tok, tok->str(), "virtual method", typeName);
} }
} }
} }