diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index fa5937a50..369a143af 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -8801,7 +8801,7 @@ static void valueFlowContainerSize(TokenList* tokenlist, value.setKnown(); valueFlowForward(containerTok->next(), containerTok, value, tokenlist, settings); } - } else if (Token::Match(tok->previous(), ">|return (|{") && astIsContainer(tok)) { + } else if (Token::Match(tok->previous(), ">|return (|{") && astIsContainer(tok) && getLibraryContainer(tok)->size_templateArgNo < 0) { std::vector values; if (Token::simpleMatch(tok, "{")) { values = getInitListSize(tok, tok->valueType(), settings, true); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 6bb7d5c6c..0115c5848 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6615,6 +6615,9 @@ private: code = "std::vector f() { return {}; }"; ASSERT_EQUALS("", isKnownContainerSizeValue(tokenValues(code, "{ } ;"), 0)); + + code = "int f() { auto a = std::array{}; return a[1]; }"; + ASSERT_EQUALS("values.size():0", isKnownContainerSizeValue(tokenValues(code, "a ["), 0)); } void valueFlowContainerElement()