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.checkVariableScope();
|
||||||
checkOther.clarifyCondition(); // not simplified because ifAssign
|
checkOther.clarifyCondition(); // not simplified because ifAssign
|
||||||
checkOther.checkComparisonOfBoolExpressionWithInt();
|
checkOther.checkComparisonOfBoolExpressionWithInt();
|
||||||
|
checkOther.checkComparisonOfBoolWithInt();
|
||||||
checkOther.checkSignOfUnsignedVariable(); // don't ignore casts (#3574)
|
checkOther.checkSignOfUnsignedVariable(); // don't ignore casts (#3574)
|
||||||
checkOther.checkIncompleteArrayFill();
|
checkOther.checkIncompleteArrayFill();
|
||||||
checkOther.checkSuspiciousStringCompare();
|
checkOther.checkSuspiciousStringCompare();
|
||||||
|
@ -103,7 +104,6 @@ public:
|
||||||
checkOther.checkMemsetZeroBytes();
|
checkOther.checkMemsetZeroBytes();
|
||||||
checkOther.checkIncorrectStringCompare();
|
checkOther.checkIncorrectStringCompare();
|
||||||
checkOther.checkIncrementBoolean();
|
checkOther.checkIncrementBoolean();
|
||||||
checkOther.checkComparisonOfBoolWithInt();
|
|
||||||
checkOther.checkSwitchCaseFallThrough();
|
checkOther.checkSwitchCaseFallThrough();
|
||||||
checkOther.checkAlwaysTrueOrFalseStringCompare();
|
checkOther.checkAlwaysTrueOrFalseStringCompare();
|
||||||
checkOther.checkModuloAlwaysTrueFalse();
|
checkOther.checkModuloAlwaysTrueFalse();
|
||||||
|
|
|
@ -144,6 +144,7 @@ private:
|
||||||
TEST_CASE(comparisonOfBoolWithInt3);
|
TEST_CASE(comparisonOfBoolWithInt3);
|
||||||
TEST_CASE(comparisonOfBoolWithInt4);
|
TEST_CASE(comparisonOfBoolWithInt4);
|
||||||
TEST_CASE(comparisonOfBoolWithInt5);
|
TEST_CASE(comparisonOfBoolWithInt5);
|
||||||
|
TEST_CASE(comparisonOfBoolWithInt6); // #4224 - integer is casted to bool
|
||||||
|
|
||||||
TEST_CASE(checkComparisonOfFuncReturningBool1);
|
TEST_CASE(checkComparisonOfFuncReturningBool1);
|
||||||
TEST_CASE(checkComparisonOfFuncReturningBool2);
|
TEST_CASE(checkComparisonOfFuncReturningBool2);
|
||||||
|
@ -3604,8 +3605,7 @@ private:
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n"
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
|
||||||
"[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.
|
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if ((x || 0x0f)==0)\n"
|
" if ((x || 0x0f)==0)\n"
|
||||||
|
@ -4730,6 +4730,13 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void duplicateIf() {
|
||||||
check("void f(int a, int &b) {\n"
|
check("void f(int a, int &b) {\n"
|
||||||
" if (a) { b = 1; }\n"
|
" if (a) { b = 1; }\n"
|
||||||
|
|
Loading…
Reference in New Issue