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

Function valueFlowFunctionDefaultParameter

lib/valueflow.cpp:5749–5776  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5747}
5748
5749static void valueFlowFunctionDefaultParameter(const TokenList& tokenlist, const SymbolDatabase& symboldatabase, ErrorLogger& errorLogger, const Settings& settings)
5750{
5751 if (!tokenlist.isCPP())
5752 return;
5753
5754 for (const Scope* scope : symboldatabase.functionScopes) {
5755 const Function* function = scope->function;
5756 if (!function)
5757 continue;
5758 for (nonneg int arg = function->minArgCount(); arg < function->argCount(); arg++) {
5759 const Variable* var = function->getArgumentVar(arg);
5760 if (var && var->hasDefault() && Token::Match(var->nameToken(), "%var% = %num%|%str%|%char%|%name% [,)]")) {
5761 const std::list<ValueFlow::Value> &values = var->nameToken()->tokAt(2)->values();
5762 std::list<ValueFlow::Value> argvalues;
5763 for (const ValueFlow::Value &value : values) {
5764 if (!value.isKnown())
5765 continue;
5766 ValueFlow::Value v(value);
5767 v.defaultArg = true;
5768 v.setPossible();
5769 argvalues.push_back(std::move(v));
5770 }
5771 if (!argvalues.empty())
5772 valueFlowInjectParameter(tokenlist, errorLogger, settings, var, scope, std::move(argvalues));
5773 }
5774 }
5775 }
5776}
5777
5778static const ValueFlow::Value* getKnownValueFromToken(const Token* tok)
5779{

Callers 1

setValuesMethod · 0.85

Calls 8

valueFlowInjectParameterFunction · 0.85
isCPPMethod · 0.80
getArgumentVarMethod · 0.80
isKnownMethod · 0.80
nameTokenMethod · 0.45
tokAtMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected