diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index b1543f4af37..db6242ab1ca 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -2328,7 +2328,7 @@ void CheckStl::uselessCalls() !tok->tokAt(4)->astParent() && tok->next()->variable() && tok->next()->variable()->isStlType(stl_containers_with_empty_and_clear)) 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() && !tok->tokAt(4)->astParent()) uselessCallsRemoveError(tok->next(), tok->strAt(3)); else if (printPerformance && tok->valueType() && tok->valueType()->type == ValueType::CONTAINER) { if (Token::Match(tok, "%var% = { %var% . begin ( ) ,") && tok->varId() == tok->tokAt(3)->varId()) diff --git a/test/teststl.cpp b/test/teststl.cpp index 84dae0b0b35..18549e08f9f 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -4835,6 +4835,12 @@ class TestStl : public TestFixture { "[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\n" "[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\n", errout_str()); + check("void f(std::string& s) {\n" // #14764 + " auto it{ std::remove(s.begin(), s.end(), 'a') };\n" + " s.erase(it, s.end());\n" + "}"); + ASSERT_EQUALS("", errout_str()); + // #4431 - fp check("bool f() {\n" " return x ? true : (y.empty());\n"