From c61d2b9f41737031b16ecca8e44526e3f15ea9c0 Mon Sep 17 00:00:00 2001 From: amai2012 Date: Mon, 16 Jun 2014 20:50:47 +0200 Subject: [PATCH] #5926 Dangerous iterator comparison using operator< on 'std::deque'. std::deque features a random access iterator, so warning stlBoundaries is a false positive --- lib/checkstl.cpp | 2 +- test/teststl.cpp | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 3f7914b2f..1d3959ca0 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -707,7 +707,7 @@ void CheckStl::stlBoundaries() const Scope * scope = symbolDatabase->functionScopes[i]; for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { // 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)); if (tok->link()) tok = tok->link(); diff --git a/test/teststl.cpp b/test/teststl.cpp index 9d3e9dbba..6382af406 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -1323,16 +1323,18 @@ private: ASSERT_EQUALS("", errout.str()); } - + template + size_t getArraylength( const T(&)[n]) { + return n; + } void stlBoundaries1() { - const int STL_CONTAINER_LIST = 9; - const std::string stlCont[STL_CONTAINER_LIST] = { - "deque", "list", "set", "multiset", "map", + const std::string stlCont[] = { + "list", "set", "multiset", "map", "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" "{\n" " std::" + stlCont[i] + "::iterator it;\n" @@ -1348,6 +1350,13 @@ private: " 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()); + + // #5926 no FP Dangerous iterator comparison using operator< on 'std::deque'. + check("void f() {\n" + " std::deque::iterator it;\n" + " for (it = ab.begin(); ab.end() > it; ++it) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void stlBoundaries2() {