diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index fe882b99413..9f416b133e3 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -488,7 +488,7 @@ void CheckStl::iterators() const int iteratorId = var->declarationId(); // 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 = nullptr; // The container this iterator can be used with diff --git a/test/teststl.cpp b/test/teststl.cpp index cabcc8eee0f..0ac868ab558 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -5155,6 +5155,13 @@ class TestStl : public TestFixture { " *it;\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("int g() {\n" // #13332 + " const std::vector v = { 1, 2, 3, 4 };\n" + " const std::vector::const_iterator a[2] = { v.begin(), v.end() };\n" + " return *a[0];\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void dereferenceInvalidIterator2() {