Skip to content

Commit bc04c0d

Browse files
Fix #14764 FP uselessCallsRemove with brace init (#8565)
1 parent a84a5a6 commit bc04c0d

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/checkstl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2327,7 +2327,7 @@ void CheckStl::uselessCalls()
23272327
!tok->tokAt(4)->astParent() &&
23282328
tok->next()->variable() && tok->next()->variable()->isStlType(stl_containers_with_empty_and_clear))
23292329
uselessCallsEmptyError(tok->next());
2330-
else if (Token::Match(tok, "[{};] std :: remove|remove_if|unique (") && tok->tokAt(5)->nextArgument())
2330+
else if (Token::Match(tok, "[{};] std :: remove|remove_if|unique (") && tok->tokAt(5)->nextArgument() && !tok->tokAt(4)->astParent())
23312331
uselessCallsRemoveError(tok->next(), tok->strAt(3));
23322332
else if (printPerformance && tok->valueType() && tok->valueType()->type == ValueType::CONTAINER) {
23332333
if (Token::Match(tok, "%var% = { %var% . begin ( ) ,") && tok->varId() == tok->tokAt(3)->varId())

test/teststl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4835,6 +4835,12 @@ class TestStl : public TestFixture {
48354835
"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\n"
48364836
"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\n", errout_str());
48374837

4838+
check("void f(std::string& s) {\n" // #14764
4839+
" auto it{ std::remove(s.begin(), s.end(), 'a') };\n"
4840+
" s.erase(it, s.end());\n"
4841+
"}");
4842+
ASSERT_EQUALS("", errout_str());
4843+
48384844
// #4431 - fp
48394845
check("bool f() {\n"
48404846
" return x ? true : (y.empty());\n"

0 commit comments

Comments
 (0)