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

Method eraseCheckLoopVar

lib/checkstl.cpp:1420–1462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1418}
1419
1420void CheckStlImpl::eraseCheckLoopVar(const Scope &scope, const Variable *var)
1421{
1422 bool inconclusiveType=false;
1423 if (!isIterator(var, inconclusiveType))
1424 return;
1425 for (const Token *tok = scope.bodyStart; tok != scope.bodyEnd; tok = tok->next()) {
1426 if (tok->str() != "(")
1427 continue;
1428 if (!Token::Match(tok->tokAt(-2), ". erase ( ++| %varid% )", var->declarationId()))
1429 continue;
1430 // Vector erases are handled by invalidContainer check
1431 if (isVector(tok->tokAt(-3)))
1432 continue;
1433 if (Token::Match(tok->astParent(), "=|return"))
1434 continue;
1435 // Iterator is invalid..
1436 int indentlevel = 0U;
1437 const Token *tok2 = tok->link();
1438 for (; tok2 != scope.bodyEnd; tok2 = tok2->next()) {
1439 if (tok2->str() == "{") {
1440 ++indentlevel;
1441 continue;
1442 }
1443 if (tok2->str() == "}") {
1444 if (indentlevel > 0U)
1445 --indentlevel;
1446 else if (Token::simpleMatch(tok2, "} else {"))
1447 tok2 = tok2->linkAt(2);
1448 continue;
1449 }
1450 if (tok2->varId() == var->declarationId()) {
1451 if (Token::simpleMatch(tok2->next(), "="))
1452 break;
1453 dereferenceErasedError(tok, tok2, tok2->str(), inconclusiveType);
1454 break;
1455 }
1456 if (indentlevel == 0U && Token::Match(tok2, "break|return|goto"))
1457 break;
1458 }
1459 if (tok2 == scope.bodyEnd)
1460 dereferenceErasedError(tok, scope.classDef, var->nameToken()->str(), inconclusiveType);
1461 }
1462}
1463
1464void CheckStlImpl::stlBoundaries()
1465{

Callers

nothing calls this directly

Calls 9

isIteratorFunction · 0.85
isVectorFunction · 0.85
nextMethod · 0.80
astParentMethod · 0.80
linkAtMethod · 0.80
simpleMatchFunction · 0.70
strMethod · 0.45
tokAtMethod · 0.45
nameTokenMethod · 0.45

Tested by

no test coverage detected