Fixed false positive: Return value of std::remove() ignored when std::remove(char*) is called (#4093)

This commit is contained in:
PKEuS 2012-08-27 14:28:16 +02:00
parent 263e13e924
commit 671f1b83d9
2 changed files with 2 additions and 1 deletions

View File

@ -1340,7 +1340,7 @@ void CheckStl::uselessCalls()
uselessCallsSubstrError(tok, true); uselessCallsSubstrError(tok, true);
} else if (Token::Match(tok, "[{}:;] %var% . empty ( ) ;") && style) } else if (Token::Match(tok, "[{}:;] %var% . empty ( ) ;") && style)
uselessCallsEmptyError(tok->next()); uselessCallsEmptyError(tok->next());
else if (Token::Match(tok, "[{};] std :: remove (")) else if (Token::Match(tok, "[{};] std :: remove (") && tok->tokAt(5)->nextArgument())
uselessCallsRemoveError(tok->next()); uselessCallsRemoveError(tok->next());
} }
} }

View File

@ -1941,6 +1941,7 @@ private:
" std::remove(a.begin(), a.end(), val);\n" " std::remove(a.begin(), a.end(), val);\n"
" x = std::remove(a.begin(), a.end(), val);\n" " x = std::remove(a.begin(), a.end(), val);\n"
" a.erase(std::remove(a.begin(), a.end(), val));\n" " a.erase(std::remove(a.begin(), a.end(), val));\n"
" std::remove(\"foo.txt\");\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:2]: (warning) Return value of std::remove() ignored. Elements remain in container.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (warning) Return value of std::remove() ignored. Elements remain in container.\n", errout.str());
} }