Fixed false positive #4039: Handle operator precedence in CheckStl::size()
This commit is contained in:
parent
985ac662ee
commit
bb068d2f78
|
@ -926,8 +926,8 @@ void CheckStl::size()
|
|||
|
||||
if (varid) {
|
||||
// check for comparison to zero
|
||||
if (Token::Match(end, "==|<=|!=|> 0") ||
|
||||
Token::Match(tok->tokAt(-2), "0 ==|>=|!=|<")) {
|
||||
if ((tok->previous() && !tok->previous()->isArithmeticalOp() && Token::Match(end, "==|<=|!=|> 0")) ||
|
||||
(end->next() && !end->next()->isArithmeticalOp() && Token::Match(tok->tokAt(-2), "0 ==|>=|!=|<"))) {
|
||||
if (isStlContainer(varid))
|
||||
sizeError(tok1);
|
||||
}
|
||||
|
|
|
@ -1449,6 +1449,12 @@ private:
|
|||
" fun(a && x.size());\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
||||
|
||||
check("void f() {\n" // #4039
|
||||
" std::list<int> x;\n"
|
||||
" fun(width % x.size() != 0);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void redundantCondition1() {
|
||||
|
|
Loading…
Reference in New Issue