diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index fba6db5a0..44d8b2cbd 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -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."; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index f2e6d4ca6..cb508786d 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -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");