diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 21a709859..83c30a245 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1002,8 +1002,11 @@ static bool valueFlowForward(Token * const startToken, for (it = values.begin(); it != values.end();) { if (it->condition || it->conditional) values.erase(it++); - else + else { + if (it->valueKind == ValueFlow::Value::Known) + it->valueKind = ValueFlow::Value::Possible; ++it; + } } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 8fcd9c999..83ce94876 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1548,6 +1548,24 @@ private: ASSERT_EQUALS(9, value.intvalue); ASSERT_EQUALS(ValueFlow::Value::ValueKind::Possible, value.valueKind); + code = "void f() {\n" + " int x = 0;\n" + " for (int i = 0; i < 10; i++) {\n" + " if (cond) {\n" + " x = 1;\n" + " break;\n" + " }\n" + " }\n" + " if (!x) {}\n" // <- possible value + "}"; + std::list values = tokenValues(code, "!"); + bool possible = false; + for (std::list::const_iterator it = values.begin(); it != values.end(); ++it) { + if (it->valueKind == ValueFlow::Value::Possible) + possible = true; + } + ASSERT_EQUALS(true, possible); + // after condition code = "int f(int x) {\n" " if (x == 4) {}\n"