diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index f013c2cfc..ca96b428a 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -138,7 +138,7 @@ void CheckStl::iterators() continue; // 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 231528f3a..a547b0ee0 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -555,6 +555,14 @@ private: " }\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #8509 Uniform initialization ignored for iterator + check("void f() {\n" + " std::vector ints;\n" + " std::vector::const_iterator iter {ints.cbegin()};\n" + " std::cout << (*iter) << std::endl;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void dereference_break() { // #3644