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
+54Lines changed: 54 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3634,12 +3634,66 @@ class TestStl : public TestFixture {
3634
3634
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n"
3635
3635
"[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i.\n", errout.str());
3636
3636
3637
+
3637
3638
check("void f(std::vector<int> & v) {\n"
3638
3639
" std::vector<int>::iterator i= v.begin();\n"
3639
3640
" if(i == v.end() && *i == *(i+1)) {}\n"
3640
3641
"}\n");
3641
3642
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i.\n"
3642
3643
"[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n", errout.str());
3644
+
3645
+
check("void f(std::vector<int> & v) {\n"
3646
+
" std::vector<int>::iterator i= v.begin();\n"
3647
+
" if(i != v.end() && *i == *(i+1)) {}\n"
3648
+
"}\n");
3649
+
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n", errout.str());
3650
+
3651
+
check("void f(std::vector<int> & v) {\n"
3652
+
" std::vector<int>::iterator i= v.begin();\n"
3653
+
" if(i != v.end()) {\n"
3654
+
" if (*(i+1) == *i) {}\n"
3655
+
" }\n"
3656
+
"}\n");
3657
+
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n", errout.str());
3658
+
3659
+
check("void f(std::vector<int> & v) {\n"
3660
+
" std::vector<int>::iterator i= v.begin();\n"
3661
+
" if(i == v.end()) { return; }\n"
3662
+
" if (*(i+1) == *i) {}\n"
3663
+
"}\n");
3664
+
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n", errout.str());
" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\n"
3674
+
" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\n"
3675
+
" if (!isalpha(*(i + 2))) {\n"
3676
+
" std::string modifier;\n"
3677
+
" modifier += *i;\n"
3678
+
" modifier += *(i + 1);\n"
3679
+
" }\n"
3680
+
" }\n"
3681
+
" }\n"
3682
+
"}\n");
3683
+
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2.\n", errout.str());
3684
+
3685
+
check("void f(std::string s) {\n"
3686
+
" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\n"
3687
+
" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\n"
0 commit comments