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

Function checkVariableAssignment

lib/checkother.cpp:3367–3384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3365}
3366
3367static bool checkVariableAssignment(const Token* tok, const ValueType* vtLhs, const Settings& settings)
3368{
3369 if (!Token::Match(tok, "%var% ;"))
3370 return false;
3371 const Variable* var = tok->variable();
3372 if (!var || !isLargeObject(var, settings))
3373 return false;
3374 if (!vtLhs || !vtLhs->isTypeEqual(var->valueType()))
3375 return false;
3376 if (findVariableChanged(tok->tokAt(2), tok->scope()->bodyEnd, /*indirect*/ 0, var->declarationId(), /*globalvar*/ false, settings))
3377 return false;
3378 if (var->isLocal() || (var->isArgument() && !var->isReference()))
3379 return true;
3380 const Scope* scope = tok->scope();
3381 while (scope && scope->type != ScopeType::eFunction)
3382 scope = scope->nestedIn;
3383 return scope && scope->function && (!scope->functionOf || scope->function->isConst() || scope->function->isStatic());
3384}
3385
3386void CheckOtherImpl::checkRedundantCopy()
3387{

Callers 2

assertWithSideEffectsMethod · 0.85
checkRedundantCopyMethod · 0.85

Calls 7

isLargeObjectFunction · 0.85
findVariableChangedFunction · 0.85
variableMethod · 0.80
isTypeEqualMethod · 0.80
scopeMethod · 0.80
isConstMethod · 0.80
tokAtMethod · 0.45

Tested by

no test coverage detected