Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,9 @@ void CheckStlImpl::redundantCondition()
const Token *var3 = var2->tokAt(7);
const Token *any2 = var3->tokAt(4);

if (any2->tokAt(3) != scope.bodyEnd)
continue;

// Check if all the "%name%" fields are the same and if all the "%any%" are the same..
if (var1->str() == var2->str() &&
var2->str() == var3->str() &&
Expand Down
10 changes: 10 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4556,6 +4556,16 @@ class TestStl : public TestFixture {
" haystack.remove(needle);"
"}");
ASSERT_EQUALS("[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\n", errout_str());

check("void g(const std::string&);\n" // #14725
"std::set<std::string> g_s;\n"
"void f(const std::string& k) {\n"
" if (g_s.find(k) != g_s.end()) {\n"
" g_s.erase(k);\n"
" g(k);\n"
" }\n"
"}");
ASSERT_EQUALS("", errout_str());
}

void missingInnerComparison1() {
Expand Down
Loading