Fix #9342 FP oppositeExpression - negated value is not opposite for bitwise logical operators (#3615)
This commit is contained in:
parent
e7b6920cf4
commit
f64097465f
|
@ -1555,9 +1555,9 @@ bool isOppositeExpression(bool cpp, const Token * const tok1, const Token * cons
|
|||
return false;
|
||||
if (isOppositeCond(true, cpp, tok1, tok2, library, pure, followVar, errors))
|
||||
return true;
|
||||
if (tok1->isUnaryOp("-"))
|
||||
if (tok1->isUnaryOp("-") && !(tok2->astParent() && tok2->astParent()->tokType() == Token::eBitOp))
|
||||
return isSameExpression(cpp, true, tok1->astOperand1(), tok2, library, pure, followVar, errors);
|
||||
if (tok2->isUnaryOp("-"))
|
||||
if (tok2->isUnaryOp("-") && !(tok2->astParent() && tok2->astParent()->tokType() == Token::eBitOp))
|
||||
return isSameExpression(cpp, true, tok2->astOperand1(), tok1, library, pure, followVar, errors);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -5773,6 +5773,15 @@ private:
|
|||
" if( *a == !(b) ) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Opposite expression on both sides of '=='.\n", errout.str());
|
||||
|
||||
check("void f(uint16_t u) {\n" // #9342
|
||||
" if (u != (u & -u))\n"
|
||||
" return false;\n"
|
||||
" if (u != (-u & u))\n"
|
||||
" return false;\n"
|
||||
" return true;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void duplicateVarExpression() {
|
||||
|
|
Loading…
Reference in New Issue