STL: refactorings
This commit is contained in:
parent
248b6aa159
commit
9b1e6c80ed
|
@ -549,11 +549,19 @@ void CheckStl::if_find()
|
||||||
const unsigned int varid = tok->varId();
|
const unsigned int varid = tok->varId();
|
||||||
if (varid > 0)
|
if (varid > 0)
|
||||||
{
|
{
|
||||||
// Locate variable declaration..
|
// Is the variable a std::string or STL container?
|
||||||
const Token * const decl = Token::findmatch(_tokenizer->tokens(), "%varid%", varid);
|
const Token * decl = Token::findmatch(_tokenizer->tokens(), "%varid%", varid);
|
||||||
if (_settings->_showAll && Token::Match(decl->tokAt(-4), ",|;|( std :: string"))
|
while (decl && !Token::Match(decl, "[;{}(,]"))
|
||||||
|
decl = decl->previous();
|
||||||
|
|
||||||
|
decl = decl->next();
|
||||||
|
|
||||||
|
// string..
|
||||||
|
if (_settings->_showAll && Token::Match(decl, "const| std :: string &|*| %varid%", varid))
|
||||||
if_findError(tok, true);
|
if_findError(tok, true);
|
||||||
else if (Token::Match(decl->tokAt(-7), ",|;|( std :: %type% < %type% >"))
|
|
||||||
|
// stl container
|
||||||
|
else if (Token::Match(decl, "const| std :: %var% < %type% > &|*| %varid%", varid))
|
||||||
if_findError(tok, false);
|
if_findError(tok, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -594,11 +602,15 @@ bool CheckStl::isStlContainer(const Token *tok)
|
||||||
const Token *type = Token::findmatch(_tokenizer->tokens(), "%varid%", tok->varId());
|
const Token *type = Token::findmatch(_tokenizer->tokens(), "%varid%", tok->varId());
|
||||||
|
|
||||||
// find where this tokens type starts
|
// find where this tokens type starts
|
||||||
while (type->previous() && !Token::Match(type->previous(), "[;{]"))
|
while (type->previous() && !Token::Match(type->previous(), "[;{,(]"))
|
||||||
type = type->previous();
|
type = type->previous();
|
||||||
|
|
||||||
|
// ignore "const"
|
||||||
|
if (type->str() == "const")
|
||||||
|
type = type->next();
|
||||||
|
|
||||||
// discard namespace if supplied
|
// discard namespace if supplied
|
||||||
if (Token::Match(type, "std ::"))
|
if (Token::simpleMatch(type, "std ::"))
|
||||||
type = type->next()->next();
|
type = type->next()->next();
|
||||||
|
|
||||||
// all possible stl containers
|
// all possible stl containers
|
||||||
|
|
Loading…
Reference in New Issue