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

Function isDeadTemporary

lib/checkautovariables.cpp:490–508  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

488}
489
490static bool isDeadTemporary(const Token* tok, const Token* expr, const Library& library)
491{
492 if (!isTemporary(tok, &library))
493 return false;
494 if (expr) {
495 if (!precedes(nextAfterAstRightmostLeaf(tok->astTop()), nextAfterAstRightmostLeaf(expr->astTop())))
496 return false;
497 const Token* parent = tok->astParent();
498 if (Token::simpleMatch(parent, "{") && Token::simpleMatch(parent->astParent(), ":"))
499 parent = parent->astParent();
500 // Is in a for loop
501 if (astIsRHS(tok) && Token::simpleMatch(parent, ":") && Token::simpleMatch(parent->astParent(), "(") && Token::simpleMatch(parent->astParent()->previous(), "for (")) {
502 const Token* braces = parent->astParent()->link()->next();
503 if (precedes(braces, expr) && precedes(expr, braces->link()))
504 return false;
505 }
506 }
507 return true;
508}
509
510static bool isEscapedReference(const Variable* var)
511{

Callers 1

checkVarLifetimeScopeMethod · 0.85

Calls 8

isTemporaryFunction · 0.85
precedesFunction · 0.85
astIsRHSFunction · 0.85
astTopMethod · 0.80
astParentMethod · 0.80
nextMethod · 0.80
simpleMatchFunction · 0.70

Tested by

no test coverage detected