diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index f551d82221f..dbd35964f9e 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -6421,9 +6421,9 @@ static std::vector getInitListSize(const Token* tok, std::vector args = getArguments(tok); if (args.empty()) return {makeContainerSizeValue(std::size_t{0}, known)}; - bool initList = true; + bool initList = tok->str() == "{"; // Try to disambiguate init list from constructor - if (args.size() < 4) { + if (initList && args.size() < 4) { initList = !isIteratorPair(args); const Token* containerTypeToken = valueType->containerTypeToken; if (valueType->container->stdStringLike) { diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index d26b339629d..1300c54b0a6 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7119,6 +7119,12 @@ class TestValueFlow : public TestFixture { " return x;\n" "}"; ASSERT_EQUALS(false, testValueOfXKnown(code, 5U, 2)); + + code = "auto f() {\n" // #13450 + " auto v = std::vector>(3, std::vector());\n" + " return v[2];\n" + "}"; + ASSERT(isKnownContainerSizeValue(tokenValues(code, "v ["), 3).empty()); } void valueFlowContainerElement()