* Fix #10426 FN (style) Condition 's.empty()' is always false * Fix test
This commit is contained in:
parent
1e14e360cb
commit
9ab4f9976d
|
@ -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%"));
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ void QString1(QString s)
|
|||
int QString2()
|
||||
{
|
||||
QString s;
|
||||
// FIXME cppcheck-suppress reademptycontainer
|
||||
// cppcheck-suppress knownConditionTrueFalse
|
||||
return s.size();
|
||||
}
|
||||
|
||||
|
|
|
@ -4305,6 +4305,18 @@ private:
|
|||
" 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()
|
||||
|
|
Loading…
Reference in New Issue