From 83b87b54b408fbff82d0ad45cb41477dc6f10319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 6 Jan 2018 22:25:13 +0100 Subject: [PATCH] Fixed #8191 (False positive iterators regression) --- lib/checkstl.cpp | 2 +- test/teststl.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 5a0efb27b..75fabdc72 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -241,7 +241,7 @@ void CheckStl::iterators() Token::Match(skipMembers(tok2->tokAt(2)), "begin|rbegin|cbegin|crbegin|find (")) { validatingToken = skipMembers(tok2->tokAt(2))->linkAt(1); containerToken = skipMembers(tok2->tokAt(2))->tokAt(-2); - if (containerToken->varId() == 0) + if (containerToken->varId() == 0 || Token::simpleMatch(validatingToken, ") .")) containerToken = nullptr; containerAssignScope = tok2->scope(); diff --git a/test/teststl.cpp b/test/teststl.cpp index d5d396e15..b9e9db7c1 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -53,6 +53,7 @@ private: TEST_CASE(iterator11); TEST_CASE(iterator12); TEST_CASE(iterator13); + TEST_CASE(iterator14); // #8191 TEST_CASE(dereference); TEST_CASE(dereference_break); // #3644 - handle "break" @@ -521,6 +522,15 @@ private: ASSERT_EQUALS("", errout.str()); } + void iterator14() { + check("void f() {\n" + " std::map x;\n" + " std::map::const_iterator it;\n" + " for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + // Dereferencing invalid pointer void dereference() { check("void f()\n"