Fixed #8360 (false positive "Ineffective call of function 'empty()'")

This commit is contained in:
Daniel Marjamäki 2018-07-10 22:57:59 +02:00
parent 7e2858f158
commit b398398dec
2 changed files with 7 additions and 0 deletions

View File

@ -1429,6 +1429,7 @@ void CheckStl::uselessCalls()
} else if (Token::simpleMatch(tok->linkAt(3)->tokAt(-2), ", 0 )")) } else if (Token::simpleMatch(tok->linkAt(3)->tokAt(-2), ", 0 )"))
uselessCallsSubstrError(tok, true); uselessCallsSubstrError(tok, true);
} else if (printWarning && Token::Match(tok, "[{};] %var% . empty ( ) ;") && } else if (printWarning && Token::Match(tok, "[{};] %var% . empty ( ) ;") &&
!tok->tokAt(4)->astParent() &&
tok->next()->variable() && tok->next()->variable()->isStlType(stl_containers_with_empty_and_clear)) tok->next()->variable() && tok->next()->variable()->isStlType(stl_containers_with_empty_and_clear))
uselessCallsEmptyError(tok->next()); uselessCallsEmptyError(tok->next());
else if (Token::Match(tok, "[{};] std :: remove|remove_if|unique (") && tok->tokAt(5)->nextArgument()) else if (Token::Match(tok, "[{};] std :: remove|remove_if|unique (") && tok->tokAt(5)->nextArgument())

View File

@ -2766,6 +2766,12 @@ private:
" return x ? true : (y.empty());\n" " return x ? true : (y.empty());\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #8360
check("void f(std::string s) {\n"
" for (;s.empty();) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void stabilityOfChecks() { void stabilityOfChecks() {