#5926 Dangerous iterator comparison using operator< on 'std::deque'.
std::deque features a random access iterator, so warning stlBoundaries is a false positive
This commit is contained in:
parent
847bb44bdd
commit
c61d2b9f41
|
@ -707,7 +707,7 @@ void CheckStl::stlBoundaries()
|
||||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||||
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||||
// Declaring iterator..
|
// Declaring iterator..
|
||||||
if (tok->str() == "<" && Token::Match(tok->previous(), "bitset|deque|list|forward_list|map|multimap|multiset|priority_queue|queue|set|stack|hash_map|hash_multimap|hash_set|unordered_map|unordered_multimap|unordered_set|unordered_multiset")) {
|
if (tok->str() == "<" && Token::Match(tok->previous(), "bitset|list|forward_list|map|multimap|multiset|priority_queue|queue|set|stack|hash_map|hash_multimap|hash_set|unordered_map|unordered_multimap|unordered_set|unordered_multiset")) {
|
||||||
const std::string& container_name(tok->strAt(-1));
|
const std::string& container_name(tok->strAt(-1));
|
||||||
if (tok->link())
|
if (tok->link())
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
|
|
|
@ -1323,16 +1323,18 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<size_t n, typename T>
|
||||||
|
size_t getArraylength( const T(&)[n]) {
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
void stlBoundaries1() {
|
void stlBoundaries1() {
|
||||||
const int STL_CONTAINER_LIST = 9;
|
const std::string stlCont[] = {
|
||||||
const std::string stlCont[STL_CONTAINER_LIST] = {
|
"list", "set", "multiset", "map",
|
||||||
"deque", "list", "set", "multiset", "map",
|
|
||||||
"multimap", "hash_map", "hash_multimap", "hash_set"
|
"multimap", "hash_map", "hash_multimap", "hash_set"
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int i = 0; i < STL_CONTAINER_LIST; ++i) {
|
for (size_t i = 0; i < getArraylength(stlCont); ++i) {
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::" + stlCont[i] + "<int>::iterator it;\n"
|
" std::" + stlCont[i] + "<int>::iterator it;\n"
|
||||||
|
@ -1348,6 +1350,13 @@ private:
|
||||||
" for (it = ab.begin(); ab.end() > it; ++it) {}\n"
|
" for (it = ab.begin(); ab.end() > it; ++it) {}\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous iterator comparison using operator< on 'std::forward_list'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous iterator comparison using operator< on 'std::forward_list'.\n", errout.str());
|
||||||
|
|
||||||
|
// #5926 no FP Dangerous iterator comparison using operator< on 'std::deque'.
|
||||||
|
check("void f() {\n"
|
||||||
|
" std::deque<int>::iterator it;\n"
|
||||||
|
" for (it = ab.begin(); ab.end() > it; ++it) {}\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void stlBoundaries2() {
|
void stlBoundaries2() {
|
||||||
|
|
Loading…
Reference in New Issue