Handle float values (#4336)

This commit is contained in:
chrchr-github 2022-08-02 22:11:31 +02:00 committed by GitHub
parent 71f9a7269f
commit 0eabe0505b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -1294,7 +1294,7 @@ void CheckCondition::checkIncorrectLogicOperator()
const std::string text = cond1str + " " + tok->str() + " " + cond2str;
incorrectLogicOperatorError(tok, text, alwaysTrue, inconclusive, errorPath);
} else if (printStyle && (firstTrue || secondTrue)) {
const int which = sufficientCondition(op1, not1, i1, op2, not2, i2, isAnd);
const int which = isfloat ? sufficientCondition(op1, not1, d1, op2, not2, d2, isAnd) : sufficientCondition(op1, not1, i1, op2, not2, i2, isAnd);
std::string text;
if (which != 0) {
text = "The condition '" + (which == 1 ? cond2str : cond1str) + "' is redundant since '" + (which == 1 ? cond1str : cond2str) + "' is sufficient.";

View File

@ -1747,6 +1747,18 @@ private:
"[test.cpp:5]: (style) Redundant condition: The condition 'x < 5' is redundant since 'x < 6' is sufficient.\n",
errout.str());
check("void f(double x, bool& b) {\n"
" b = x > 6.5 && x > 5.5;\n"
" c = x > 5.5 || x > 6.5;\n"
" d = x < 6.5 && x < 5.5;\n"
" e = x < 5.5 || x < 6.5;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: The condition 'x > 5.5' is redundant since 'x > 6.5' is sufficient.\n"
"[test.cpp:3]: (style) Redundant condition: The condition 'x > 6.5' is redundant since 'x > 5.5' is sufficient.\n"
"[test.cpp:4]: (style) Redundant condition: The condition 'x < 6.5' is redundant since 'x < 5.5' is sufficient.\n"
"[test.cpp:5]: (style) Redundant condition: The condition 'x < 5.5' is redundant since 'x < 6.5' is sufficient.\n",
errout.str());
check("void f(const char *p) {\n" // #10320
" if (!p || !*p || *p != 'x') {}\n"
"}\n");