Fixed #4224 (False positive: Comparison of a boolean with an integer (neglecting a cast))
This commit is contained in:
parent
dba51c906e
commit
bf91454136
|
@ -75,6 +75,7 @@ public:
|
|||
checkOther.checkVariableScope();
|
||||
checkOther.clarifyCondition(); // not simplified because ifAssign
|
||||
checkOther.checkComparisonOfBoolExpressionWithInt();
|
||||
checkOther.checkComparisonOfBoolWithInt();
|
||||
checkOther.checkSignOfUnsignedVariable(); // don't ignore casts (#3574)
|
||||
checkOther.checkIncompleteArrayFill();
|
||||
checkOther.checkSuspiciousStringCompare();
|
||||
|
@ -103,7 +104,6 @@ public:
|
|||
checkOther.checkMemsetZeroBytes();
|
||||
checkOther.checkIncorrectStringCompare();
|
||||
checkOther.checkIncrementBoolean();
|
||||
checkOther.checkComparisonOfBoolWithInt();
|
||||
checkOther.checkSwitchCaseFallThrough();
|
||||
checkOther.checkAlwaysTrueOrFalseStringCompare();
|
||||
checkOther.checkModuloAlwaysTrueFalse();
|
||||
|
|
|
@ -144,6 +144,7 @@ private:
|
|||
TEST_CASE(comparisonOfBoolWithInt3);
|
||||
TEST_CASE(comparisonOfBoolWithInt4);
|
||||
TEST_CASE(comparisonOfBoolWithInt5);
|
||||
TEST_CASE(comparisonOfBoolWithInt6); // #4224 - integer is casted to bool
|
||||
|
||||
TEST_CASE(checkComparisonOfFuncReturningBool1);
|
||||
TEST_CASE(checkComparisonOfFuncReturningBool2);
|
||||
|
@ -3604,8 +3605,7 @@ private:
|
|||
" a++;\n"
|
||||
"}\n"
|
||||
);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n"
|
||||
"[test.cpp:2]: (warning) Comparison of a boolean with an integer.\n", errout.str()); // The second message appears because the code is simplified to "true == 6". Its neither wrong nor necessary.
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
|
||||
|
||||
check("void f(int x) {\n"
|
||||
" if ((x || 0x0f)==0)\n"
|
||||
|
@ -4730,6 +4730,13 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void comparisonOfBoolWithInt6() { // #4224 - integer is casted to bool
|
||||
check("void SetVisible(bool b, int i) {\n"
|
||||
" if (b == (bool)i) { }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void duplicateIf() {
|
||||
check("void f(int a, int &b) {\n"
|
||||
" if (a) { b = 1; }\n"
|
||||
|
|
Loading…
Reference in New Issue