diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index a0cf3330a..14e3d11d9 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1929,6 +1929,10 @@ static void execute(const Token *expr, *result = result1 / result2; else if (expr->str() == "%") *result = result1 % result2; + else if (expr->str() == "<<") + *result = result1 << result2; + else if (expr->str() == ">>") + *result = result1 >> result2; } else if (expr->str() == "&&") { diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 7d5b5d3d2..f986326e4 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1968,6 +1968,19 @@ private: value = valueOfTok(code, "&"); ASSERT_EQUALS(0, value.intvalue); ASSERT(value.isKnown()); + + // Ticket #7139 + // "<<" in third expression of for + code = "void f(void) {\n" + " int bit, x;\n" + " for (bit = 1, x = 0; bit < 128; bit = bit << 1, x++) {\n" + " z = x;\n" // <- known value [0..6] + " }\n" + "}\n"; + ASSERT_EQUALS(true, testValueOfX(code, 4U, 0)); + ASSERT_EQUALS(true, testValueOfX(code, 4U, 6)); + ASSERT_EQUALS(false, testValueOfX(code, 4U, 7)); + ASSERT(value.isKnown()); } };