Fix #12087 Library: add Container::Action::FIND_CONST (#5579)

This commit is contained in:
chrchr-github 2023-10-20 21:22:06 +02:00 committed by GitHub
parent b61feaf77f
commit 41bd28c0b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 18 additions and 9 deletions

View File

@ -698,6 +698,7 @@
<value>push</value>
<value>pop</value>
<value>find</value>
<value>find-const</value>
<value>insert</value>
<value>erase</value>
<value>change-content</value>

View File

@ -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">

View File

@ -1966,7 +1966,7 @@ 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)) {
@ -1974,7 +1974,7 @@ bool isConstFunctionCall(const Token* ftok, const Library& library)
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 {

View File

@ -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;

View File

@ -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")

View File

@ -197,6 +197,7 @@ public:
PUSH,
POP,
FIND,
FIND_CONST,
INSERT,
ERASE,
CHANGE_CONTENT,

View File

@ -8300,6 +8300,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;

View File

@ -811,6 +811,7 @@ private:
" <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"
@ -851,6 +852,7 @@ private:
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);