From 59cd1879db14856bb9d4e019ba451113a9759b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 9 Apr 2014 10:32:56 +0200 Subject: [PATCH] Fixed #5467 (False positive incorrectly claiming use after erase) --- lib/checkstl.cpp | 3 +++ test/teststl.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 1f9e763d7..9b78f768e 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -77,6 +77,9 @@ void CheckStl::iterators() if (!var || !var->isLocal() || !Token::Match(var->typeEndToken(), "iterator|const_iterator|reverse_iterator|const_reverse_iterator|auto")) continue; + if (var->typeEndToken()->str() == "auto" && !Token::Match(var->typeEndToken(), "auto %var% ; %var% = %var% . begin|end ( )")) + continue; + if (var->type()) { // If it is defined, ensure that it is defined like an iterator // look for operator* and operator++ const Function* end = var->type()->getFunction("operator*"); diff --git a/test/teststl.cpp b/test/teststl.cpp index da13ae3af..cd6e79e71 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -506,6 +506,13 @@ private: " std::cout << (*iter) << std::endl;\n" "}"); ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:5]: (error) Iterator 'iter' used after element has been erased.\n", errout.str()); + + check("void f() {\n" + " auto x = *myList.begin();\n" + " myList.erase(x);\n" + " auto b = x.first;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void STLSize() {