From 32f0cbb6ad31ecda2f8af65449e0079461409a6e Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 8 Nov 2015 09:42:28 +0100 Subject: [PATCH] Fixed false positive eraseDereference with range-based for-loops (#7106) --- lib/checkstl.cpp | 2 +- test/teststl.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 0c0f0a54b..147703466 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -89,7 +89,7 @@ void CheckStl::iterators() } // the validIterator flag says if the iterator has a valid value or not - bool validIterator = Token::Match(var->nameToken()->next(), "[(=]"); + bool validIterator = Token::Match(var->nameToken()->next(), "[(=:]"); const Scope* invalidationScope = 0; // The container this iterator can be used with diff --git a/test/teststl.cpp b/test/teststl.cpp index bf2de5dd6..49937f1d6 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -97,6 +97,7 @@ private: TEST_CASE(stlBoundaries3); TEST_CASE(stlBoundaries4); // #4364 TEST_CASE(stlBoundaries5); // #4352 + TEST_CASE(stlBoundaries6); // #7106 // if (str.find("ab")) TEST_CASE(if_find); @@ -1478,6 +1479,17 @@ private: ASSERT_EQUALS("[test.cpp:8]: (error) Invalid iterator 'i' used.\n", errout.str()); } + void stlBoundaries6() { // #7106 + check("void foo(std::vector& vec) {\n" + " for (Function::iterator BB : vec) {\n" + " for (int Inst : *BB)\n" + " {\n" + " }\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void if_find() { // ---------------------------