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/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ void CheckCondition::alwaysTrueFalse()
tok->astParent() && Token::Match(tok->astTop()->astOperand1(), "if|while") && !tok->astTop()->astOperand1()->isConstexpr() &&
(Token::Match(tok->astParent(), "%oror%|&&") || Token::Match(tok->astParent()->astOperand1(), "if|while"));
const bool constValExpr = tok->isNumber() && Token::Match(tok->astParent(),"%oror%|&&|?"); // just one number in boolean expression
const bool compExpr = Token::Match(tok, "%comp%|!"); // a compare expression
const bool compExpr = Token::Match(tok, "%comp%|!|("); // a compare expression
const bool ternaryExpression = Token::simpleMatch(tok->astParent(), "?");
const bool returnExpression = Token::simpleMatch(tok->astTop(), "return") && (tok->isComparisonOp() || Token::Match(tok, "&&|%oror%"));

Expand Down
2 changes: 1 addition & 1 deletion test/cfg/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void QString1(QString s)
int QString2()
{
QString s;
// FIXME cppcheck-suppress reademptycontainer
// cppcheck-suppress knownConditionTrueFalse
return s.size();
}

Expand Down
12 changes: 12 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4305,6 +4305,18 @@ class TestCondition : public TestFixture {
" else if (x < 1) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());

// #10426
check("void f() {\n"
" std::string s;\n"
" for (; !s.empty();) {}\n"
" for (; s.empty();) {}\n"
" if (s.empty()) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Condition '!s.empty()' is always false\n"
"[test.cpp:4]: (style) Condition 's.empty()' is always true\n"
"[test.cpp:5]: (style) Condition 's.empty()' is always true\n",
errout.str());
}

void alwaysTrueSymbolic()
Expand Down