Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5155,6 +5155,13 @@ class TestStl : public TestFixture {
" *it;\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("int g() {\n" // #13332
" const std::vector<int> v = { 1, 2, 3, 4 };\n"
" const std::vector<int>::const_iterator a[2] = { v.begin(), v.end() };\n"
" return *a[0];\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void dereferenceInvalidIterator2() {
Expand Down