Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ static bool isZeroBoundCond(const Token * const cond, bool reverse)

const Token* op = reverse ? cond->astOperand1() : cond->astOperand2();
if (!op->hasKnownIntValue())
return false;
return true;

// Assume unsigned
const bool isZero = op->getKnownIntValue() == 0;
Expand Down
6 changes: 6 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2682,6 +2682,12 @@ class TestCondition : public TestFixture {
check("void f1(const std::string &s) { if(s.empty()) if(42 < s.size()) {}}");
ASSERT_EQUALS("[test.cpp:1:43] -> [test.cpp:1:53]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str());

check("void f(const std::string& s, int n) {\n" // #14716
" if (s.size() < n)\n"
" if (s.empty()) {}\n"
"}");
ASSERT_EQUALS("", errout_str());

// TODO: These are identical condition since size cannot be negative
check("void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}");
ASSERT_EQUALS("", errout_str());
Expand Down
Loading