From bce0776417d10e29a970b406b8aa7fdfed775244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 1 Jun 2017 15:16:07 +0200 Subject: [PATCH] Fixed #7795 (ValueFlow: Value is not known after conditional increment ) --- lib/valueflow.cpp | 7 +++++++ test/testvalueflow.cpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 0c13d0909..e7a40d0ae 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1317,6 +1317,13 @@ static bool valueFlowForward(Token * const startToken, bailout(tokenlist, errorLogger, tok2, "variable " + var->name() + " valueFlowForward, conditional return is assumed to be executed"); return false; } + } else if (indentlevel <= 0 && + Token::simpleMatch(tok2->link()->previous(), "else {") && + !isReturnScope(tok2->link()->tokAt(-2)) && + isVariableChanged(tok2->link(), tok2, varid, settings)) { + std::list::iterator it; + for (it = values.begin(); it != values.end(); ++it) + it->changeKnownToPossible(); } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index e1d9083d2..6af78922d 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -2245,6 +2245,13 @@ private: ASSERT_EQUALS(9, value.intvalue); ASSERT(value.isPossible()); + code = "void f(int c) {\n" + " int x = 0;\n" + " if (c) {} else { x++; }\n" + " return x + 2;\n" // <- possible value + "}"; + ASSERT(isNotKnownValues(code, "+")); + code = "void f() {\n" " int x = 0;\n" " fred.dostuff(x);\n"