diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 14e3d11d9..e36d47ff6 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1674,7 +1674,18 @@ static void valueFlowAfterAssign(TokenList *tokenlist, SymbolDatabase* symboldat } } - valueFlowForward(tok, endOfVarScope, var, varid, values, constValue, tokenlist, errorLogger, settings); + // Skip RHS + const Token *nextExpression = tok->astOperand2(); + for (;;) { + if (nextExpression->astOperand2()) + nextExpression = nextExpression->astOperand2(); + else if (nextExpression->isUnaryPreOp()) + nextExpression = nextExpression->astOperand1(); + else break; + } + nextExpression = nextExpression->next(); + + valueFlowForward(const_cast(nextExpression), endOfVarScope, var, varid, values, constValue, tokenlist, errorLogger, settings); } } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index f986326e4..adec1c001 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -772,6 +772,13 @@ private: ASSERT_EQUALS(false, testValueOfX(code, 4U, 9)); ASSERT_EQUALS(true, testValueOfX(code, 4U, 8)); + code = "void x() {\n" + " int x = value ? 6 : 0;\n" + " x =\n" + " 1 + x;\n" + "}"; + ASSERT_EQUALS(false, testValueOfX(code, 4U, 7)); + code = "void f() {\n" " int x = 0;\n" " y = x += z;\n"