assume all std::*::size() and std::*::empty() are const in CheckClass::checkConstFunc()

This commit is contained in:
Robert Reif 2011-07-30 10:30:31 -04:00
parent addcec704f
commit e687ee9a9a
1 changed files with 3 additions and 12 deletions

View File

@ -1632,21 +1632,12 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Token *tok)
} }
else if (Token::Match(tok1, "%var% . size|empty ( )") && tok1->varId()) else if (Token::Match(tok1, "%var% . size|empty ( )") && tok1->varId())
{ {
// STL container size() is const // assume all std::*::size() and std::*::empty() are const
static const char STL_CONTAINER_LIST[] = "bitset|deque|list|map|multimap|multiset|priority_queue|queue|set|stack|hash_map|hash_multimap|hash_set|string|vector";
const Variable *var = symbolDatabase->getVariableFromVarId(tok1->varId()); const Variable *var = symbolDatabase->getVariableFromVarId(tok1->varId());
if (var) if (var && Token::simpleMatch(var->typeStartToken(), "std ::"))
{
const Token *tok2 = var->typeStartToken();
// skip namespace if present
if (Token::simpleMatch(tok2, "std ::"))
tok2 = tok2->tokAt(2);
// check for STL container
if (Token::Match(tok2, STL_CONTAINER_LIST))
tok1 = tok1->tokAt(4); tok1 = tok1->tokAt(4);
} }
}
// delete.. // delete..
else if (tok1->str() == "delete") else if (tok1->str() == "delete")