Skip to content

Commit 3ea3af0

Browse files
Partial fix for #14037 Triplicate warnings for same issue (comparison with bool) (#7727)
1 parent d44e45c commit 3ea3af0

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

lib/checkcondition.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,8 +2042,9 @@ void CheckCondition::checkCompareValueOutOfTypeRange()
20422042
break;
20432043
}
20442044
}
2045-
if (error)
2046-
compareValueOutOfTypeRangeError(valueTok, typeTok->valueType()->str(), kiv, result);
2045+
if (!error || diag(tok))
2046+
continue;
2047+
compareValueOutOfTypeRangeError(valueTok, typeTok->valueType()->str(), kiv, result);
20472048
}
20482049
}
20492050
}

test/cfg/std.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,7 +2746,6 @@ void bool_isfinite(float f)
27462746
{
27472747
// cppcheck-suppress compareBoolExpressionWithInt
27482748
// cppcheck-suppress compareValueOutOfTypeRangeError
2749-
// cppcheck-suppress knownConditionTrueFalse
27502749
if (std::isfinite(f)==123) {}
27512750
}
27522751

@@ -2769,7 +2768,6 @@ void bool_isgreater(float f1, float f2)
27692768
{
27702769
// cppcheck-suppress compareBoolExpressionWithInt
27712770
// cppcheck-suppress compareValueOutOfTypeRangeError
2772-
// cppcheck-suppress knownConditionTrueFalse
27732771
if (std::isgreater(f1,f2)==123) {}
27742772
}
27752773

@@ -2792,7 +2790,6 @@ void bool_isgreaterequal(float f1, float f2)
27922790
{
27932791
// cppcheck-suppress compareBoolExpressionWithInt
27942792
// cppcheck-suppress compareValueOutOfTypeRangeError
2795-
// cppcheck-suppress knownConditionTrueFalse
27962793
if (std::isgreaterequal(f1, f2)==123) {}
27972794
}
27982795

@@ -2815,7 +2812,6 @@ void bool_isinf(float f)
28152812
{
28162813
// cppcheck-suppress compareBoolExpressionWithInt
28172814
// cppcheck-suppress compareValueOutOfTypeRangeError
2818-
// cppcheck-suppress knownConditionTrueFalse
28192815
if (std::isinf(f)==123) {}
28202816
}
28212817

test/testcondition.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6231,6 +6231,12 @@ class TestCondition : public TestFixture {
62316231
"[test.cpp:14:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\n"
62326232
"[test.cpp:17:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\n",
62336233
errout_str());
6234+
6235+
check("void f(bool b) {\n" // #14037
6236+
" if (b != 2) {}\n"
6237+
"}\n", dinit(CheckOptions, $.s = &settingsUnix64));
6238+
ASSERT_EQUALS("[test.cpp:2:14]: (style) Comparing expression of type 'bool' against value 2. Condition is always true. [compareValueOutOfTypeRangeError]\n",
6239+
errout_str());
62346240
}
62356241

62366242
void knownConditionCast() {

0 commit comments

Comments
 (0)