diff --git a/lib/checkother.cpp b/lib/checkother.cpp index a18ae900a..d901c1f90 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -106,7 +106,7 @@ void CheckOther::clarifyCalculation() } else if (cond->isName() || cond->isNumber()) { - if (Token::Match(cond->previous(),("return|+|-|,|(|"+op).c_str())) + if (Token::Match(cond->previous(),("return|=|+|-|,|(|"+op).c_str())) clarifyCalculationError(cond, op); } } diff --git a/test/testother.cpp b/test/testother.cpp index addc62bbe..b1410d6d6 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2296,6 +2296,11 @@ private: " std::cout << x << 1 ? 2 : 3;\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for << and ?\n", errout.str()); + + check("void f() {\n" + " int ab = a - b ? 2 : 3;\n" + "}"); + ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for - and ?\n", errout.str()); } // clarify conditions with = and comparison