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

Function pruneLifetimes

lib/checkstl.cpp:718–736  ·  view source on GitHub ↗

First it groups the lifetimes together using std::partition with the lifetimes that refer to the same token or token of a subexpression. Then it finds the lifetime in that group that refers to the "highest" parent using std::min_element and adds that to the vector.

Source from the content-addressed store, hash-verified

716// First it groups the lifetimes together using std::partition with the lifetimes that refer to the same token or token of a subexpression.
717// Then it finds the lifetime in that group that refers to the "highest" parent using std::min_element and adds that to the vector.
718static std::vector<ValueFlow::Value> pruneLifetimes(std::vector<ValueFlow::Value> lifetimes)
719{
720 std::vector<ValueFlow::Value> result;
721 auto start = lifetimes.begin();
722 while (start != lifetimes.end())
723 {
724 const Token* tok1 = start->tokvalue;
725 auto it = std::partition(start, lifetimes.end(), [&](const ValueFlow::Value& v) {
726 const Token* tok2 = v.tokvalue;
727 return start->lifetimeKind == v.lifetimeKind && (astHasToken(tok1, tok2) || astHasToken(tok2, tok1));
728 });
729 auto root = std::min_element(start, it, [](const ValueFlow::Value& x, const ValueFlow::Value& y) {
730 return x.tokvalue != y.tokvalue && astHasToken(x.tokvalue, y.tokvalue);
731 });
732 result.push_back(*root);
733 start = it;
734 }
735 return result;
736}
737
738static ValueFlow::Value getLifetimeIteratorValue(const Token* tok, MathLib::bigint path = 0)
739{

Callers 1

getLifetimeIteratorValueFunction · 0.85

Calls 4

astHasTokenFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected