diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index f1340f4a8..97c1a9b2b 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -3478,6 +3478,8 @@ static void valueFlowContainerReverse(const Token *tok, unsigned int containerId while (nullptr != (tok = tok->previous())) { if (Token::Match(tok, "[{}]")) break; + if (Token::Match(tok, "return|break|continue")) + break; if (tok->varId() != containerId) continue; if (Token::Match(tok, "%name% =")) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 277054aa3..cbc04a29b 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -3307,6 +3307,19 @@ private: "}"; ASSERT_EQUALS("", isPossibleContainerSizeValue(tokenValues(code, "v ["), 10)); + code = "void f(std::vector params) {\n" + " switch(x) {\n" + " case CMD_RESPONSE:\n" + " if(y) { break; }\n" + " params[2];\n" // <- container use + " break;\n" + " case CMD_DELETE:\n" + " if (params.size() < 2) { }\n" // <- condition + " break;\n" + " }\n" + "}"; + ASSERT(tokenValues(code, "params [ 2 ]").empty()); + // valueFlowContainerForward code = "void f(const std::list &ints) {\n" " if (ints.empty()) {}\n"