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,20 +1632,11 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Token *tok)
}
else if (Token::Match(tok1, "%var% . size|empty ( )") && tok1->varId())
{
// STL container size() is 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";
// assume all std::*::size() and std::*::empty() are const
const Variable *var = symbolDatabase->getVariableFromVarId(tok1->varId());
if (var)
{
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);
}
if (var && Token::simpleMatch(var->typeStartToken(), "std ::"))
tok1 = tok1->tokAt(4);
}
// delete..