Skip to content
Merged
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
1 change: 1 addition & 0 deletions cfg/cppcheck-cfg.rng
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@
<value>push</value>
<value>pop</value>
<value>find</value>
<value>find-const</value>
Comment thread
chrchr-github marked this conversation as resolved.
<value>insert</value>
<value>erase</value>
<value>change-content</value>
Expand Down
12 changes: 6 additions & 6 deletions cfg/std.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8758,12 +8758,12 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
<function name="back" yields="item"/>
<function name="data" yields="buffer"/>
<function name="c_str" yields="buffer-nt"/>
<function name="find" action="find"/>
<function name="rfind" action="find"/>
<function name="find_last_of" action="find"/>
<function name="find_last_not_of" action="find"/>
<function name="find_first_of" action="find"/>
<function name="find_first_not_of" action="find"/>
<function name="find" action="find-const"/>
<function name="rfind" action="find-const"/>
<function name="find_last_of" action="find-const"/>
<function name="find_last_not_of" action="find-const"/>
<function name="find_first_of" action="find-const"/>
<function name="find_first_not_of" action="find-const"/>
</access>
</container>
<container id="stdBasicString" startPattern="std :: basic_string &lt;" inherits="stdAllString">
Expand Down
4 changes: 2 additions & 2 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1966,15 +1966,15 @@ bool isConstFunctionCall(const Token* ftok, const Library& library)
return false;
if (container->getYield(ftok->str()) != Library::Container::Yield::NO_YIELD)
return true;
if (container->getAction(ftok->str()) == Library::Container::Action::FIND)
if (container->getAction(ftok->str()) == Library::Container::Action::FIND_CONST)
return true;
return false;
} else if (const Library::Function* lf = library.getFunction(ftok)) {
if (lf->ispure)
return true;
if (lf->containerYield != Library::Container::Yield::NO_YIELD)
return true;
if (lf->containerAction == Library::Container::Action::FIND)
if (lf->containerAction == Library::Container::Action::FIND_CONST)
return true;
return false;
} else {
Expand Down
4 changes: 3 additions & 1 deletion lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,9 @@ void CheckStl::if_find()
}
}

if (container && container->getAction(funcTok->str()) == Library::Container::Action::FIND) {
Library::Container::Action action{};
if (container &&
((action = container->getAction(funcTok->str())) == Library::Container::Action::FIND || action == Library::Container::Action::FIND_CONST)) {
if (if_findCompare(funcTok->next(), container->stdStringLike))
continue;

Expand Down
2 changes: 2 additions & 0 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ Library::Container::Action Library::Container::actionFrom(const std::string& act
return Container::Action::POP;
if (actionName == "find")
return Container::Action::FIND;
if (actionName == "find-const")
return Container::Action::FIND_CONST;
if (actionName == "insert")
return Container::Action::INSERT;
if (actionName == "erase")
Expand Down
1 change: 1 addition & 0 deletions lib/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class CPPCHECKLIB Library {
PUSH,
POP,
FIND,
FIND_CONST,
INSERT,
ERASE,
CHANGE_CONTENT,
Expand Down
1 change: 1 addition & 0 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8242,6 +8242,7 @@ bool ValueFlow::isContainerSizeChanged(const Token* tok, int indirect, const Set
}
break;
case Library::Container::Action::FIND:
case Library::Container::Action::FIND_CONST:
case Library::Container::Action::CHANGE_CONTENT:
case Library::Container::Action::CHANGE_INTERNAL:
break;
Expand Down
2 changes: 2 additions & 0 deletions test/testlibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ class TestLibrary : public TestFixture {
" <function name=\"c_str\" yields=\"buffer-nt\"/>\n"
" <function name=\"front\" yields=\"item\"/>\n"
" <function name=\"find\" action=\"find\"/>\n"
" <function name=\"cfind\" action=\"find-const\"/>\n"
" </access>\n"
" </container>\n"
" <container id=\"B\" startPattern=\"std :: B &lt;\" inherits=\"A\" opLessAllowed=\"false\">\n"
Expand Down Expand Up @@ -851,6 +852,7 @@ class TestLibrary : public TestFixture {
ASSERT_EQ(Library::Container::Action::PUSH, A.getAction("push_back"));
ASSERT_EQ(Library::Container::Action::POP, A.getAction("pop_back"));
ASSERT_EQ(Library::Container::Action::FIND, A.getAction("find"));
ASSERT_EQ(Library::Container::Action::FIND_CONST, A.getAction("cfind"));
ASSERT_EQ(Library::Container::Action::NO_ACTION, A.getAction("foo"));

ASSERT_EQUALS(B.type_templateArgNo, 1);
Expand Down