You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/teststl.cpp
+21-1Lines changed: 21 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1140,6 +1140,20 @@ class TestStl : public TestFixture {
1140
1140
"[test.cpp:3:11]: note: Assuming that condition 'i>5' is not redundant\n"
1141
1141
"[test.cpp:5:13]: note: Access out of bounds\n",
1142
1142
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());
1143
1157
}
1144
1158
1145
1159
voiditerator1() {
@@ -2441,7 +2455,7 @@ class TestStl : public TestFixture {
2441
2455
" if (it == v.end()) {}\n"
2442
2456
" v.erase(it);\n"
2443
2457
"}\n");
2444
-
ASSERT_EQUALS("[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\n",
2458
+
ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\n",
2445
2459
errout_str());
2446
2460
2447
2461
check("void f() {\n"
@@ -5161,6 +5175,12 @@ class TestStl : public TestFixture {
5161
5175
"}\n");
5162
5176
ASSERT_EQUALS("[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\n",
5163
5177
errout_str());
5178
+
5179
+
check("void f(std::string& a, const std::string& b) {\n"
5180
+
" a += b.c_str();\n"
5181
+
"}\n");
5182
+
ASSERT_EQUALS("[test.cpp:2:7]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\n",
0 commit comments