Skip to content

Commit fa31ebf

Browse files
committed
Fixed danmar#7349 (checker 'inefficient find()' unintentionally used for find_first_of())
1 parent 8ef17e7 commit fa31ebf

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/checkstl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ void CheckStl::if_find()
700700

701701
if (printWarning && container->getYield(funcTok->str()) == Library::Container::ITERATOR)
702702
if_findError(tok, false);
703-
else if (printPerformance && container->stdStringLike)
703+
else if (printPerformance && container->stdStringLike && funcTok->str() == "find")
704704
if_findError(tok, true);
705705
} else if (printWarning && Token::Match(tok, "std :: find|find_if (")) {
706706
// check that result is checked properly

test/teststl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,12 @@ class TestStl : public TestFixture {
17261726
" if (foo(s.find(\"abc\"))) { }\n"
17271727
"}");
17281728
ASSERT_EQUALS("", errout.str());
1729+
1730+
// #7349 - std::string::find_first_of
1731+
check("void f(const std::string &s) {\n"
1732+
" if (s.find_first_of(\"abc\")==0) { }\n"
1733+
"}");
1734+
ASSERT_EQUALS("", errout.str());
17291735
}
17301736

17311737

0 commit comments

Comments
 (0)