convert remainder of CheckClass::noMemset to use symbol database
This commit is contained in:
parent
b05c192b56
commit
5314cc02b2
|
@ -698,62 +698,34 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
|
|||
checkMemsetType(start, tok, type->derivedFrom[i].scope);
|
||||
}
|
||||
|
||||
// Warn if type is a class that contains any virtual functions
|
||||
std::list<Function>::const_iterator func;
|
||||
|
||||
for (func = type->functionList.begin(); func != type->functionList.end(); ++func)
|
||||
{
|
||||
if (func->isVirtual)
|
||||
memsetError(tok, tok->str(), "virtual method", type->classDef->str());
|
||||
}
|
||||
|
||||
// Warn if type is a class or struct that contains any std::* variables
|
||||
const Token *tstruct = type->classDef;
|
||||
const std::string &typeName = tstruct->str();
|
||||
std::list<Variable>::const_iterator var;
|
||||
|
||||
for (; tstruct; tstruct = tstruct->next())
|
||||
for (var = type->varlist.begin(); var != type->varlist.end(); ++var)
|
||||
{
|
||||
if (tstruct->str() == "}")
|
||||
break;
|
||||
|
||||
// struct with function? skip function body..
|
||||
if (Token::simpleMatch(tstruct, ") {"))
|
||||
// don't warn if variable static or const
|
||||
if (!var->isStatic() && !var->isConst())
|
||||
{
|
||||
tstruct = tstruct->next()->link();
|
||||
if (!tstruct)
|
||||
break;
|
||||
}
|
||||
const Token *tok1 = var->typeStartToken();
|
||||
|
||||
// before a statement there must be either:
|
||||
// * private:|protected:|public:
|
||||
// * { } ;
|
||||
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);
|
||||
// skip mutable token
|
||||
if (var->isMutable())
|
||||
tok1 = tok1->next();
|
||||
|
||||
else if (Token::Match(tstruct->next(), "std :: %type% <"))
|
||||
{
|
||||
// backup the type
|
||||
const std::string typestr(tstruct->strAt(3));
|
||||
// check for std:: type that is not a pointer or reference
|
||||
if (Token::simpleMatch(tok1, "std ::") && !Token::Match(var->nameToken(), "*|&"))
|
||||
memsetError(tok, tok->str(), "'std::" + tok1->strAt(2) + "'", type->classDef->str());
|
||||
|
||||
// check if it's a pointer variable..
|
||||
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);
|
||||
/** @todo warn if type is class/struct that doesn't require initialization */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue