Skip to content

Commit 64db6ed

Browse files
Fix #13332 FP eraseDereference for iterator in array (danmar#7039)
1 parent 61b75e6 commit 64db6ed

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/checkstl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ void CheckStl::iterators()
488488
const int iteratorId = var->declarationId();
489489

490490
// the validIterator flag says if the iterator has a valid value or not
491-
bool validIterator = Token::Match(var->nameToken()->next(), "[(=:{]");
491+
bool validIterator = Token::Match(var->nameToken()->next(), "[(=:{[]");
492492
const Scope* invalidationScope = nullptr;
493493

494494
// The container this iterator can be used with

test/teststl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5155,6 +5155,13 @@ class TestStl : public TestFixture {
51555155
" *it;\n"
51565156
"}\n");
51575157
ASSERT_EQUALS("", errout_str());
5158+
5159+
check("int g() {\n" // #13332
5160+
" const std::vector<int> v = { 1, 2, 3, 4 };\n"
5161+
" const std::vector<int>::const_iterator a[2] = { v.begin(), v.end() };\n"
5162+
" return *a[0];\n"
5163+
"}\n");
5164+
ASSERT_EQUALS("", errout_str());
51585165
}
51595166

51605167
void dereferenceInvalidIterator2() {

0 commit comments

Comments
 (0)