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);
|
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
|
// Warn if type is a class or struct that contains any std::* variables
|
||||||
const Token *tstruct = type->classDef;
|
std::list<Variable>::const_iterator var;
|
||||||
const std::string &typeName = tstruct->str();
|
|
||||||
|
|
||||||
for (; tstruct; tstruct = tstruct->next())
|
for (var = type->varlist.begin(); var != type->varlist.end(); ++var)
|
||||||
{
|
{
|
||||||
if (tstruct->str() == "}")
|
// don't warn if variable static or const
|
||||||
break;
|
if (!var->isStatic() && !var->isConst())
|
||||||
|
|
||||||
// struct with function? skip function body..
|
|
||||||
if (Token::simpleMatch(tstruct, ") {"))
|
|
||||||
{
|
{
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue