Fixed #6373: Support bitops in clarifyCalculation check

This commit is contained in:
PKEuS 2014-12-30 17:55:29 +01:00
parent 69b31a0743
commit 9e8a66ee40
2 changed files with 8 additions and 1 deletions

View File

@ -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?

View File

@ -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"