Use library config for unstable containers instead of hardcoded values (#2585)
* Use library config for unstable containers instead of hardcoded values * Fix xml validation
This commit is contained in:
parent
58e3f19ed8
commit
a22a77c1fc
|
@ -69,7 +69,9 @@
|
|||
<container id="boostMultiSet" startPattern="boost :: flat_multiset|multiset <" inherits="stdMultiSet"/>
|
||||
<container id="boostMap" startPattern="boost :: map|flat_map|unordered_map <" inherits="stdMap"/>
|
||||
<container id="boostSet" startPattern="boost :: set|flat_set|unordered_set <" inherits="stdSet"/>
|
||||
<container id="boostVectorDeque" startPattern="boost :: deque|vector|small_vector|stable_vector|static_vector <" inherits="stdVectorDeque"/>
|
||||
<container id="boostVector" startPattern="boost :: vector|small_vector <" inherits="stdVector"/>
|
||||
<container id="boostStableVector" startPattern="boost :: stable_vector|static_vector <" inherits="stdVectorDeque"/>
|
||||
<container id="boostDeque" startPattern="boost :: deque <" inherits="stdDeque"/>
|
||||
<!-- ########## Boost smart pointers ########## -->
|
||||
<!-- https://www.boost.org/doc/libs/1_70_0/libs/smart_ptr/doc/html/smart_ptr.html -->
|
||||
<smart-pointer class-name="boost::scoped_ptr"/>
|
||||
|
|
|
@ -391,6 +391,19 @@
|
|||
<value>std-like</value>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="unstable">
|
||||
<list>
|
||||
<oneOrMore>
|
||||
<data type="string"/>
|
||||
<choice>
|
||||
<value>erase</value>
|
||||
<value>insert</value>
|
||||
</choice>
|
||||
</oneOrMore>
|
||||
</list>
|
||||
</attribute>
|
||||
</optional>
|
||||
<empty/>
|
||||
</element>
|
||||
<element name="size">
|
||||
|
|
10
cfg/std.cfg
10
cfg/std.cfg
|
@ -7871,7 +7871,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
|
|||
<function name="crend" yields="end-iterator"/>
|
||||
</access>
|
||||
</container>
|
||||
<container id="stdVectorDeque" startPattern="std :: vector|deque <" inherits="stdContainer" opLessAllowed="true">
|
||||
<container id="stdVectorDeque" inherits="stdContainer" opLessAllowed="true">
|
||||
<size>
|
||||
<function name="push_back" action="push"/>
|
||||
<function name="emplace_back" action="push"/>
|
||||
|
@ -7889,6 +7889,12 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
|
|||
<function name="reserve" action="change-internal"/>
|
||||
</access>
|
||||
</container>
|
||||
<container id="stdVector" startPattern="std :: vector <" inherits="stdVectorDeque">
|
||||
<type unstable="erase insert" />
|
||||
</container>
|
||||
<container id="stdDeque" startPattern="std :: deque <" inherits="stdVectorDeque">
|
||||
<type unstable="erase insert" />
|
||||
</container>
|
||||
<container id="stdArray" startPattern="std :: array <" inherits="stdContainer" opLessAllowed="true">
|
||||
<size templateParameter="1">
|
||||
<function name="max_size" yields="size"/>
|
||||
|
@ -7987,7 +7993,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
|
|||
</access>
|
||||
</container>
|
||||
<container id="stdAllString" inherits="stdContainer" opLessAllowed="true" hasInitializerListConstructor="false">
|
||||
<type string="std-like"/>
|
||||
<type string="std-like" unstable="erase insert"/>
|
||||
<size>
|
||||
<function name="push_back" action="push"/>
|
||||
<function name="pop_back" action="pop"/>
|
||||
|
|
|
@ -710,12 +710,35 @@ void CheckStl::mismatchingContainers()
|
|||
|
||||
static bool isInvalidMethod(const Token * tok)
|
||||
{
|
||||
if (Token::Match(tok->next(), ". assign|clear"))
|
||||
if (Token::Match(tok->next(), ". assign|clear|swap"))
|
||||
return true;
|
||||
if (Token::Match(tok->next(), "%assign%"))
|
||||
return true;
|
||||
if (isVector(tok) && Token::Match(tok->next(), ". insert|emplace|emplace_back|push_back|erase|pop_back|reserve ("))
|
||||
return true;
|
||||
if (const Library::Container * c = tok->valueType()->container) {
|
||||
Library::Container::Action action = c->getAction(tok->strAt(2));
|
||||
if (c->unstableErase) {
|
||||
if (action == Library::Container::Action::ERASE)
|
||||
return true;
|
||||
}
|
||||
if (c->unstableInsert) {
|
||||
if (action == Library::Container::Action::RESIZE)
|
||||
return true;
|
||||
if (action == Library::Container::Action::CLEAR)
|
||||
return true;
|
||||
if (action == Library::Container::Action::PUSH)
|
||||
return true;
|
||||
if (action == Library::Container::Action::POP)
|
||||
return true;
|
||||
if (action == Library::Container::Action::INSERT)
|
||||
return true;
|
||||
if (action == Library::Container::Action::CHANGE)
|
||||
return true;
|
||||
if (action == Library::Container::Action::CHANGE_INTERNAL)
|
||||
return true;
|
||||
if (Token::Match(tok->next(), ". insert|emplace"))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
static std::vector<std::string> getnames(const char *names)
|
||||
{
|
||||
|
@ -500,6 +501,14 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
|||
const char* const associative = containerNode->Attribute("associative");
|
||||
if (associative)
|
||||
container.stdAssociativeLike = std::string(associative) == "std-like";
|
||||
const char* const unstable = containerNode->Attribute("unstable");
|
||||
if (unstable) {
|
||||
std::string unstableType = unstable;
|
||||
if (unstableType.find("erase") != std::string::npos)
|
||||
container.unstableErase = true;
|
||||
if (unstableType.find("insert") != std::string::npos)
|
||||
container.unstableInsert = true;
|
||||
}
|
||||
} else
|
||||
unknown_elements.insert(containerNodeName);
|
||||
}
|
||||
|
|
|
@ -197,7 +197,9 @@ public:
|
|||
stdStringLike(false),
|
||||
stdAssociativeLike(false),
|
||||
opLessAllowed(true),
|
||||
hasInitializerListConstructor(false) {
|
||||
hasInitializerListConstructor(false),
|
||||
unstableErase(false),
|
||||
unstableInsert(false) {
|
||||
}
|
||||
|
||||
enum class Action {
|
||||
|
@ -221,6 +223,8 @@ public:
|
|||
bool stdAssociativeLike;
|
||||
bool opLessAllowed;
|
||||
bool hasInitializerListConstructor;
|
||||
bool unstableErase;
|
||||
bool unstableInsert;
|
||||
|
||||
Action getAction(const std::string& function) const {
|
||||
const std::map<std::string, Function>::const_iterator i = functions.find(function);
|
||||
|
|
Loading…
Reference in New Issue