Avoid clarifyCalculation warning for 'x % 16 ? 1 : 0' expression. Fixes FP seen in daca@home. It seems likely that the order is understood otherwise the ternary calculation could easily be simplified away.
This commit is contained in:
parent
e32ccb591b
commit
d901edd4af
|
@ -168,8 +168,8 @@ void CheckOther::clarifyCalculation()
|
|||
if (tok->astOperand1()->tokType() == Token::eBitOp && Token::Match(tok->astOperand2()->astOperand1(), "%char%") && Token::Match(tok->astOperand2()->astOperand2(), "%char%"))
|
||||
continue;
|
||||
|
||||
// bitand operation in lhs with known integer value => probably no mistake
|
||||
if (tok->astOperand1()->str() == "&" && tok->astOperand1()->isBinaryOp()) {
|
||||
// 2nd operand in lhs has known integer value => probably no mistake
|
||||
if (tok->astOperand1()->isBinaryOp() && tok->astOperand1()->astOperand2()->hasKnownIntValue()) {
|
||||
const Token *op = tok->astOperand1()->astOperand2();
|
||||
if (op->isNumber())
|
||||
continue;
|
||||
|
|
|
@ -4236,12 +4236,12 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f(char c) {\n"
|
||||
" printf(\"%i\", 1 + 1 ? 1 : 2);\n" // "1+1" is simplified away
|
||||
" printf(\"%i\", a + b ? 1 : 2);\n"
|
||||
"}",nullptr,false,false,false);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '+' and '?'.\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" std::cout << x << 1 ? 2 : 3;\n"
|
||||
" std::cout << x << y ? 2 : 3;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '<<' and '?'.\n", errout.str());
|
||||
|
||||
|
@ -4281,6 +4281,9 @@ private:
|
|||
check("void f(int x) { return x & 16 ? 1 : 0; }");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f(int x) { return x % 16 ? 1 : 0; }");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue