Handle float values (#4336)
This commit is contained in:
parent
71f9a7269f
commit
0eabe0505b
|
@ -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.";
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue