MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / isIterator

Function isIterator

lib/checkstl.cpp:407–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

405}
406
407static bool isIterator(const Variable *var, bool& inconclusiveType)
408{
409 // Check that its an iterator
410 if (!var || !var->isLocal() || !Token::Match(var->typeEndToken(), "iterator|const_iterator|reverse_iterator|const_reverse_iterator|auto"))
411 return false;
412
413 inconclusiveType = false;
414 if (var->typeEndToken()->str() == "auto")
415 return (var->nameToken()->valueType() && var->nameToken()->valueType()->type == ValueType::Type::ITERATOR);
416
417 if (var->type()) { // If it is defined, ensure that it is defined like an iterator
418 // look for operator* and operator++
419 const Function* end = var->type()->getFunction("operator*");
420 const Function* incOperator = var->type()->getFunction("operator++");
421 if (!end || end->argCount() > 0 || !incOperator)
422 return false;
423
424 inconclusiveType = true; // heuristics only
425 }
426
427 return true;
428}
429
430static std::string getContainerName(const Token *containerToken)
431{

Callers 2

iteratorsMethod · 0.85
eraseCheckLoopVarMethod · 0.85

Calls 4

typeMethod · 0.80
strMethod · 0.45
nameTokenMethod · 0.45
getFunctionMethod · 0.45

Tested by

no test coverage detected