diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 679f5ef71..9f2ea005b 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5479,7 +5479,7 @@ static void valueFlowContainerForward(Token *tok, nonneg int containerId, ValueF } if (Token::simpleMatch(tok, ") {") && Token::Match(tok->link()->previous(), "while|for|if (")) { const Token *start = tok->next(); - if (isContainerSizeChanged(containerId, start, start->link())) + if (isContainerSizeChanged(containerId, start, start->link()) || isEscapeScope(start, nullptr)) break; tok = start->link(); if (Token::simpleMatch(tok, "} else {")) { diff --git a/test/testother.cpp b/test/testother.cpp index 7800f2879..00afe2e15 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4658,8 +4658,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void duplicateExpression10() - { + void duplicateExpression10() { // #9485 check("int f() {\n" " const int a = 1;\n" diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 27a3e0a6b..3c48f2477 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -4191,6 +4191,18 @@ private: "}"; ASSERT_EQUALS(0U, tokenValues(code, "v . size ( )").size()); + // if + code = "bool f(std::vector&) {\n" // #9532 + " return false;\n" + "}\n" + "int g() {\n" + " std::vector v;\n" + " if (f(v) || v.empty())\n" + " return 0;\n" + " return v[0];\n" + "}\n"; + ASSERT_EQUALS(0U, tokenValues(code, "v [ 0 ]").size()); + // container size => yields code = "void f() {\n" " std::string s = \"abcd\";\n"