diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 6a6698dab..77697c898 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2859,12 +2859,12 @@ void ValueFlow::setValues(TokenList *tokenlist, SymbolDatabase* symboldatabase, valueFlowFunctionReturn(tokenlist, errorLogger); valueFlowBitAnd(tokenlist); valueFlowOppositeCondition(symboldatabase, settings); - valueFlowForLoop(tokenlist, symboldatabase, errorLogger, settings); valueFlowBeforeCondition(tokenlist, symboldatabase, errorLogger, settings); valueFlowAfterMove(tokenlist, symboldatabase, errorLogger, settings); valueFlowAfterAssign(tokenlist, symboldatabase, errorLogger, settings); valueFlowAfterCondition(tokenlist, symboldatabase, errorLogger, settings); valueFlowSwitchVariable(tokenlist, symboldatabase, errorLogger, settings); + valueFlowForLoop(tokenlist, symboldatabase, errorLogger, settings); valueFlowSubFunction(tokenlist, errorLogger, settings); valueFlowFunctionDefaultParameter(tokenlist, symboldatabase, errorLogger, settings); } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 4388e7c40..f9e2f65db 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1847,7 +1847,6 @@ private: "}\n"; ASSERT_EQUALS(false, testValueOfX(code, 9U, 11)); - // hang code = "void f() {\n" " for(int i = 0; i < 20; i++)\n" @@ -1867,6 +1866,14 @@ private: "}"; ASSERT_EQUALS(false, testValueOfX(code, 6U, 10)); + // #7886 - valueFlowForLoop must be called after valueFlowAfterAssign + code = "void f() {\n" + " int sz = 4;\n" + " int x,y;\n" + " for(x=0,y=0; x < sz && y < 10; x++)\n" + " a = x;\n" // <- max value is 3 + "}"; + ASSERT_EQUALS(true, testValueOfX(code, 5U, 3)); } void valueFlowSubFunction() {