Change symbol database such that the typestart token skips over type modifiers (const/static/mutable).
This fixes checking for the case of a memset() on a static variable.
This commit is contained in:
parent
031670f93f
commit
3fc1db51d1
|
@ -775,10 +775,6 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
|
|||
{
|
||||
const Token *tok1 = var->typeStartToken();
|
||||
|
||||
// skip mutable token
|
||||
if (var->isMutable())
|
||||
tok1 = tok1->next();
|
||||
|
||||
// check for std:: type that is not a pointer or reference
|
||||
if (Token::simpleMatch(tok1, "std ::") && !Token::Match(var->nameToken()->previous(), "*|&"))
|
||||
memsetError(tok, tok->str(), "'std::" + tok1->strAt(2) + "'", type->classDef->str());
|
||||
|
|
|
@ -1557,7 +1557,6 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess)
|
|||
// This is the start of a statement
|
||||
const Token *vartok = NULL;
|
||||
const Token *typetok = NULL;
|
||||
const Token *typestart = tok;
|
||||
|
||||
// Is it const..?
|
||||
bool isConst = false;
|
||||
|
@ -1588,6 +1587,9 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess)
|
|||
isConst = true;
|
||||
}
|
||||
|
||||
// the start of the type tokens does not include the above modifiers
|
||||
const Token *typestart = tok;
|
||||
|
||||
bool isClass = false;
|
||||
|
||||
if (Token::Match(tok, "struct|union"))
|
||||
|
|
|
@ -3184,6 +3184,17 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a virtual method\n", errout.str());
|
||||
|
||||
checkNoMemset("class Fred\n"
|
||||
"{\n"
|
||||
" virtual ~Fred();\n"
|
||||
"};\n"
|
||||
"void f()\n"
|
||||
"{\n"
|
||||
" static Fred fred;\n"
|
||||
" memset(&fred, 0, sizeof(fred));\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a virtual method\n", errout.str());
|
||||
|
||||
checkNoMemset("class Fred\n"
|
||||
"{\n"
|
||||
"};\n"
|
||||
|
|
Loading…
Reference in New Issue