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

Function isInScope

lib/checkautovariables.cpp:437–460  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

435//---------------------------------------------------------------------------
436
437static bool isInScope(const Token * tok, const Scope * scope)
438{
439 if (!tok)
440 return false;
441 if (!scope)
442 return false;
443 const Variable * var = tok->variable();
444 if (var && (var->isGlobal() || var->isStatic() || var->isExtern()))
445 return false;
446 if (tok->scope() && !tok->scope()->isClassOrStructOrUnion() && tok->scope()->isNestedIn(scope))
447 return true;
448 if (!var)
449 return false;
450 if (var->isArgument() && !var->isReference()) {
451 const Scope * tokScope = tok->scope();
452 if (!tokScope)
453 return false;
454 if (std::any_of(tokScope->nestedList.cbegin(), tokScope->nestedList.cend(), [&](const Scope* argScope) {
455 return argScope && argScope->isNestedIn(scope);
456 }))
457 return true;
458 }
459 return false;
460}
461
462static bool isDeadScope(const Token * tok, const Scope * scope)
463{

Callers 1

checkVarLifetimeScopeMethod · 0.85

Calls 3

variableMethod · 0.80
scopeMethod · 0.80
isGlobalMethod · 0.45

Tested by

no test coverage detected