diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 55efb483d..bee285611 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -245,7 +245,9 @@ void CheckOther::clarifyCalculation() const Scope * scope = symbolDatabase->functionScopes[i]; for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { // ? operator where lhs is arithmetical expression - if (tok->str() != "?" || !tok->astOperand1() || !tok->astOperand1()->isArithmeticalOp() || !tok->astOperand1()->isCalculation()) + if (tok->str() != "?" || !tok->astOperand1() || !tok->astOperand1()->isCalculation()) + continue; + if (!tok->astOperand1()->isArithmeticalOp() && tok->astOperand1()->type() != Token::eBitOp) continue; // Is code clarified by parentheses already? diff --git a/test/testother.cpp b/test/testother.cpp index 4db3fe5b6..3eac441e4 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3751,6 +3751,11 @@ private: "}"); 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()); + // ticket #195 check("int f(int x, int y) {\n" " return x >> ! y ? 8 : 2;\n"