Fixed false positive stlSize for code like "foo + 1 > bar.size()" (#4584)

This commit is contained in:
PKEuS 2013-02-16 02:50:25 -08:00
parent b27a3c802c
commit 0d316af4f2
2 changed files with 14 additions and 2 deletions

View File

@ -951,8 +951,8 @@ void CheckStl::size()
}
// check for comparison to one
if ((tok->previous() && !tok->previous()->isArithmeticalOp() && Token::Match(end, ">=|< 1")) ||
(end->next() && !end->next()->isArithmeticalOp() && Token::Match(tok->tokAt(-2), "1 <=|>"))) {
if ((tok->previous() && !tok->previous()->isArithmeticalOp() && Token::Match(end, ">=|< 1") && !end->tokAt(2)->isArithmeticalOp()) ||
(end->next() && !end->next()->isArithmeticalOp() && Token::Match(tok->tokAt(-2), "1 <=|>") && !tok->tokAt(-3)->isArithmeticalOp())) {
if (isContainerSizeSlow(tok1))
sizeError(tok1);
}

View File

@ -1572,6 +1572,18 @@ private:
" fun(width % x.size() != 0);\n"
"}");
ASSERT_EQUALS("", errout.str());
// #4584
check("void f() {\n"
" std::list<int> x;\n"
" if (foo + 1 > x.size()) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" std::list<int> x;\n"
" if (x.size() < 1 + foo) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void redundantCondition1() {