diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 2485ecdca..e042b3729 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -160,8 +160,8 @@ void CheckOther::clarifyCalculation() if (!tok->astOperand1()->isArithmeticalOp() && tok->astOperand1()->tokType() != Token::eBitOp) continue; - // bit operation in lhs and pointer in rhs => no clarification is needed - if (tok->astOperand1()->tokType() == Token::eBitOp && tok->astOperand2()->valueType() && tok->astOperand2()->valueType()->pointer > 0) + // non-pointer calculation in lhs and pointer in rhs => no clarification is needed + if (tok->astOperand1()->isBinaryOp() && Token::Match(tok->astOperand1(), "%or%|&|%|*|/") && tok->astOperand2()->valueType() && tok->astOperand2()->valueType()->pointer > 0) continue; // bit operation in lhs and char literals in rhs => probably no mistake diff --git a/test/testother.cpp b/test/testother.cpp index 963703eef..f696b792b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4272,6 +4272,9 @@ private: check("void f(int x) { const char *p = x & 1 ? \"1\" : \"0\"; }"); ASSERT_EQUALS("", errout.str()); + check("void foo() { x = a % b ? \"1\" : \"0\"; }"); + ASSERT_EQUALS("", errout.str()); + check("void f(int x) { return x & 1 ? '1' : '0'; }"); ASSERT_EQUALS("", errout.str());