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

Method byRef

lib/valueflow.cpp:2110–2149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2108
2109 template<class Predicate>
2110 bool byRef(Token* tok,
2111 const TokenList& tokenlist,
2112 ErrorLogger& errorLogger,
2113 const Settings& settings,
2114 const Predicate& pred,
2115 SourceLocation loc = SourceLocation::current())
2116 {
2117 if (!argtok)
2118 return false;
2119 bool update = false;
2120 for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(argtok, settings)) {
2121 if (!settings.certainty.isEnabled(Certainty::inconclusive) && lt.inconclusive)
2122 continue;
2123 if (!lt.token)
2124 return false;
2125 if (!pred(lt.token))
2126 return false;
2127 ErrorPath er = errorPath;
2128 er.insert(er.end(), lt.errorPath.cbegin(), lt.errorPath.cend());
2129 er.emplace_back(argtok, message);
2130
2131 ValueFlow::Value value;
2132 value.valueType = ValueFlow::Value::ValueType::LIFETIME;
2133 value.lifetimeScope = ValueFlow::Value::LifetimeScope::Local;
2134 value.tokvalue = lt.token;
2135 value.errorPath = std::move(er);
2136 value.lifetimeKind = type;
2137 value.setInconclusive(lt.inconclusive || inconclusive);
2138 // Don't add the value a second time
2139 if (std::find(tok->values().cbegin(), tok->values().cend(), value) != tok->values().cend())
2140 return false;
2141 if (settings.debugnormal)
2142 setSourceLocation(value, loc, tok);
2143 setTokenValue(tok, std::move(value), settings);
2144 update = true;
2145 }
2146 if (update && forward)
2147 forwardLifetime(tok, tokenlist, errorLogger, settings);
2148 return update;
2149 }
2150
2151 bool byRef(Token* tok,
2152 const TokenList& tokenlist,

Calls 6

getLifetimeTokensFunction · 0.85
setSourceLocationFunction · 0.85
setTokenValueFunction · 0.85
setInconclusiveMethod · 0.80
isEnabledMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected