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

Function isSameIteratorContainerExpression

lib/checkstl.cpp:694–714  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

692}
693
694static bool isSameIteratorContainerExpression(const Token* tok1,
695 const Token* tok2,
696 const Settings& settings,
697 ValueFlow::Value::LifetimeKind kind = ValueFlow::Value::LifetimeKind::Iterator)
698{
699 if (isSameExpression(false, tok1, tok2, settings, false, false)) {
700 return !astIsContainerOwned(tok1) || !isTemporary(tok1, &settings.library);
701 }
702 if (astContainerYield(tok2, settings.library) == Library::Container::Yield::ITEM)
703 return true;
704 if (kind == ValueFlow::Value::LifetimeKind::Address || kind == ValueFlow::Value::LifetimeKind::Iterator) {
705 const auto address1 = getAddressContainer(tok1);
706 const auto address2 = getAddressContainer(tok2);
707 return std::any_of(address1.begin(), address1.end(), [&](const Token* tok1) {
708 return std::any_of(address2.begin(), address2.end(), [&](const Token* tok2) {
709 return isSameExpression(false, tok1, tok2, settings, false, false);
710 });
711 });
712 }
713 return false;
714}
715
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.

Callers 2

checkIteratorPairMethod · 0.85

Calls 7

isSameExpressionFunction · 0.85
astIsContainerOwnedFunction · 0.85
isTemporaryFunction · 0.85
astContainerYieldFunction · 0.85
getAddressContainerFunction · 0.85
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected