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

Method fromFunctionArg

lib/valueflow.cpp:2086–2107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2084 }
2085
2086 static LifetimeStore fromFunctionArg(const Function * f, const Token *tok, const Variable *var, const TokenList &tokenlist, const Settings& settings, ErrorLogger &errorLogger) {
2087 if (!var)
2088 return LifetimeStore{};
2089 if (!var->isArgument())
2090 return LifetimeStore{};
2091 const int n = getArgumentPos(var, f);
2092 if (n < 0)
2093 return LifetimeStore{};
2094 std::vector<const Token *> args = getArguments(tok);
2095 if (n >= args.size()) {
2096 if (settings.debugwarnings)
2097 bailout(tokenlist,
2098 errorLogger,
2099 tok,
2100 "Argument mismatch: Function '" + tok->str() + "' returning lifetime from argument index " +
2101 std::to_string(n) + " but only " + std::to_string(args.size()) +
2102 " arguments are available.");
2103 return LifetimeStore{};
2104 }
2105 const Token *argtok2 = args[n];
2106 return LifetimeStore{argtok2, "Passed to '" + tok->expressionString() + "'.", ValueFlow::Value::LifetimeKind::Object};
2107 }
2108
2109 template<class Predicate>
2110 bool byRef(Token* tok,

Callers

nothing calls this directly

Calls 5

getArgumentPosFunction · 0.85
getArgumentsFunction · 0.70
sizeMethod · 0.45
strMethod · 0.45
expressionStringMethod · 0.45

Tested by

no test coverage detected