Correct false positives compareBoolExpressionWithInt (0U)
This commit is contained in:
parent
0fc59d0228
commit
5c2960713f
|
@ -353,11 +353,12 @@ void CheckBool::checkComparisonOfBoolExpressionWithInt()
|
|||
continue;
|
||||
|
||||
if (numTok->isNumber()) {
|
||||
if (numTok->str() == "0" &&
|
||||
const MathLib::bigint num = MathLib::toLongNumber(numTok->str());
|
||||
if (num==0 &&
|
||||
(numInRhs ? Token::Match(tok, ">|==|!=")
|
||||
: Token::Match(tok, "<|==|!=")))
|
||||
continue;
|
||||
if (numTok->str() == "1" &&
|
||||
if (num==1 &&
|
||||
(numInRhs ? Token::Match(tok, "<|==|!=")
|
||||
: Token::Match(tok, ">|==|!=")))
|
||||
continue;
|
||||
|
|
|
@ -538,6 +538,19 @@ private:
|
|||
" return a > b or c < d;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("int f() {\n"
|
||||
" return (a < b) != 0U;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("int f() {\n"
|
||||
" return (a < b) != 0x0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("int f() {\n"
|
||||
" return (a < b) != 42U;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
|
||||
}
|
||||
|
||||
void checkComparisonOfFuncReturningBool1() {
|
||||
|
|
Loading…
Reference in New Issue