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

Function getLifetimeIteratorValue

lib/checkstl.cpp:738–755  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

736}
737
738static ValueFlow::Value getLifetimeIteratorValue(const Token* tok, MathLib::bigint path = 0)
739{
740 auto findIterVal = [](const std::vector<ValueFlow::Value>& values, const std::vector<ValueFlow::Value>::const_iterator beg) {
741 return std::find_if(beg, values.cend(), [](const ValueFlow::Value& v) {
742 return v.lifetimeKind == ValueFlow::Value::LifetimeKind::Iterator;
743 });
744 };
745 std::vector<ValueFlow::Value> values = pruneLifetimes(ValueFlow::getLifetimeObjValues(tok, false, path));
746 auto it = findIterVal(values, values.begin());
747 if (it != values.end()) {
748 auto it2 = findIterVal(values, it + 1);
749 if (it2 == values.cend())
750 return *it;
751 }
752 if (values.size() == 1)
753 return values.front();
754 return ValueFlow::Value{};
755}
756
757bool CheckStlImpl::checkIteratorPair(const Token* tok1, const Token* tok2)
758{

Calls 5

pruneLifetimesFunction · 0.85
frontMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected