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

Function getCommonValuesFromTokens

lib/valueflow.cpp:5790–5812  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5788}
5789
5790static std::vector<ValueFlow::Value> getCommonValuesFromTokens(const std::vector<const Token*>& toks)
5791{
5792 if (toks.empty())
5793 return {};
5794 std::vector<ValueFlow::Value> result;
5795 std::copy_if(toks.front()->values().begin(),
5796 toks.front()->values().end(),
5797 std::back_inserter(result),
5798 [&](const ValueFlow::Value& v) {
5799 if (!v.isKnown() && !v.isImpossible())
5800 return false;
5801 return (v.isIntValue() || v.isContainerSizeValue() || v.isFloatValue());
5802 });
5803 std::for_each(toks.begin() + 1, toks.end(), [&](const Token* tok) {
5804 auto it = std::remove_if(result.begin(), result.end(), [&](const ValueFlow::Value& v) {
5805 return std::none_of(tok->values().begin(), tok->values().end(), [&](const ValueFlow::Value& v2) {
5806 return v.equalValue(v2) && v.valueKind == v2.valueKind;
5807 });
5808 });
5809 result.erase(it, result.end());
5810 });
5811 return result;
5812}
5813
5814static void setFunctionReturnValue(const Function* f,
5815 Token* tok,

Callers 1

valueFlowFunctionReturnFunction · 0.85

Calls 7

frontMethod · 0.80
isKnownMethod · 0.80
isImpossibleMethod · 0.80
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected