From 7ddc4f4569f0c4b764bf068a42114f6dbf6ca69c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 26 Sep 2024 15:50:01 +0200 Subject: [PATCH 1/2] Update valueflow.cpp --- lib/valueflow.cpp | 2 ++ 1 file changed, 2 insertions(+) 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) From d0797ad1463ba060f2a530bafa17cdd1ece5bd57 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 26 Sep 2024 15:53:11 +0200 Subject: [PATCH 2/2] Update testvalueflow.cpp --- test/testvalueflow.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) 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()