Skip to content

Commit 662c6ce

Browse files
Update teststl.cpp
1 parent 212e735 commit 662c6ce

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎test/teststl.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,20 @@ class TestStl : public TestFixture {
11401140
"[test.cpp:3:11]: note: Assuming that condition 'i>5' is not redundant\n"
11411141
"[test.cpp:5:13]: note: Access out of bounds\n",
11421142
errout_str());
1143+
1144+
check("void f(std::vector<int>& v) {\n"
1145+
" std::vector<int>::iterator it;\n"
1146+
" for (it = v.begin(); it != v.end(); ++it) {\n"
1147+
" if (*it == 0)\n"
1148+
" break;\n"
1149+
" }\n"
1150+
" v.erase(it);\n"
1151+
"}\n", s);
1152+
ASSERT_EQUALS("[test.cpp:4:13]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\n"
1153+
"[test.cpp:7:7]: warning: Either the condition is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\n"
1154+
"[test.cpp:3:29]: note: Assuming that condition 'it!=v.end()' is not redundant\n"
1155+
"[test.cpp:7:7]: note: Either the condition is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds.\n",
1156+
errout_str());
11431157
}
11441158

11451159
void iterator1() {

0 commit comments

Comments
 (0)