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
+42Lines changed: 42 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2674,6 +2674,48 @@ class TestStl : public TestFixture {
2674
2674
" std::fill_n(v.begin(), n, 0);\n"
2675
2675
"}\n");
2676
2676
ASSERT_EQUALS("", errout_str());
2677
+
2678
+
// all container size values are checked, not only the first one
2679
+
check("void f(bool b) {\n"
2680
+
" const std::vector<int> v0{1,2,3,4,5};\n"
2681
+
" std::vector<int> v1;\n"
2682
+
" if (b)\n"
2683
+
" v1.resize(3);\n"
2684
+
" else\n"
2685
+
" v1.resize(10);\n"
2686
+
" std::copy(v0.begin(), v0.end(), v1.begin());\n"
2687
+
"}\n");
2688
+
ASSERT_EQUALS("[test.cpp:8:45]: (error) The algorithm 'std::copy' accesses 5 elements through the iterator 'v1.begin()' but only 3 elements are available. [algorithmOutOfBounds]\n",
2689
+
errout_str());
2690
+
2691
+
check("void f(bool b) {\n"
2692
+
" const std::vector<int> v0{1,2,3,4,5};\n"
2693
+
" std::vector<int> v1;\n"
2694
+
" if (b)\n"
2695
+
" v1.resize(5);\n"
2696
+
" else\n"
2697
+
" v1.resize(10);\n"
2698
+
" std::copy(v0.begin(), v0.end(), v1.begin());\n"
2699
+
"}\n");
2700
+
ASSERT_EQUALS("", errout_str());
2701
+
2702
+
// all iterator position values are checked as well
2703
+
check("void f(bool b) {\n"
2704
+
" const std::vector<int> v0{1,2,3,4};\n"
2705
+
" std::vector<int> v1(5);\n"
2706
+
" auto it = b ? v1.begin() : v1.begin() + 3;\n"
2707
+
" std::copy(v0.begin(), v0.end(), it);\n"
2708
+
"}\n");
2709
+
ASSERT_EQUALS("[test.cpp:5:37]: (error) The algorithm 'std::copy' accesses 4 elements through the iterator 'it' but only 2 elements are available. [algorithmOutOfBounds]\n",
0 commit comments