diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 855fcc556e8..1b15bcd8d9d 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5377,6 +5377,8 @@ static std::vector getInitListSize(const Token* tok, initList = true; else if (args.size() == 1 && valueFlowIsSameContainerType(vt, tok->astOperand2(), settings)) initList = false; // copy ctor + else if (args.size() == 2 && (!args[0]->valueType() || !args[1]->valueType())) // might be unknown iterators + initList = false; } } if (!initList) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 33eab3b875d..7a6dc7e6329 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6992,6 +6992,14 @@ class TestValueFlow : public TestFixture { " if (s.empty()) {}\n" "}"; ASSERT_EQUALS("", isPossibleContainerSizeValue(tokenValues(code, "s . empty"), 0)); + + code = "int f(const std::string& str) {\n" + " std::istringstream iss(str);\n" + " std::vector v{ std::istream_iterator(iss), {} };\n" + " auto x = v.size();\n" + " return x;\n" + "}"; + ASSERT_EQUALS(false, testValueOfXKnown(code, 5U, 2)); } void valueFlowContainerElement()