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

Function getInitListSize

lib/valueflow.cpp:6564–6596  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6562}
6563
6564static std::vector<ValueFlow::Value> getInitListSize(const Token* tok,
6565 const ValueType* valueType,
6566 const Settings& settings,
6567 bool known = true)
6568{
6569 std::vector<const Token*> args = getArguments(tok);
6570 if (args.empty())
6571 return {makeContainerSizeValue(MathLib::bigint{0}, known)};
6572 bool initList = tok->str() == "{";
6573 // Try to disambiguate init list from constructor
6574 if (initList && args.size() < 4) {
6575 initList = !isIteratorPair(args);
6576 const Token* containerTypeToken = valueType->containerTypeToken;
6577 if (valueType->container->stdStringLike) {
6578 initList = astIsGenericChar(args[0]) && !astIsPointer(args[0]);
6579 } else if (containerTypeToken) {
6580 ValueType vt = ValueType::parseDecl(containerTypeToken, settings);
6581 if (vt.pointer > 0 && astIsPointer(args[0]))
6582 initList = true;
6583 else if (vt.type == ValueType::ITERATOR && astIsIterator(args[0]))
6584 initList = true;
6585 else if (vt.isIntegral() && astIsIntegral(args[0], false))
6586 initList = true;
6587 else if (args.size() == 1 && valueFlowIsSameContainerType(vt, tok->astOperand2(), valueType->container->view, settings))
6588 initList = false; // copy ctor
6589 else if (args.size() == 2 && (!args[0]->valueType() || !args[1]->valueType())) // might be unknown iterators
6590 initList = false;
6591 }
6592 }
6593 if (!initList)
6594 return getContainerSizeFromConstructorArgs(args, valueType->container, known);
6595 return {makeContainerSizeValue(args.size(), known)};
6596}
6597
6598static std::vector<ValueFlow::Value> getContainerSizeFromConstructor(const Token* tok,
6599 const ValueType* valueType,

Callers 2

valueFlowContainerSizeFunction · 0.85

Calls 14

makeContainerSizeValueFunction · 0.85
isIteratorPairFunction · 0.85
astIsGenericCharFunction · 0.85
astIsPointerFunction · 0.85
astIsIteratorFunction · 0.85
astIsIntegralFunction · 0.85
isIntegralMethod · 0.80
astOperand2Method · 0.80
getArgumentsFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected