| 6562 | } |
| 6563 | |
| 6564 | static 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 | |
| 6598 | static std::vector<ValueFlow::Value> getContainerSizeFromConstructor(const Token* tok, |
| 6599 | const ValueType* valueType, |
no test coverage detected