Skip to content

Commit 8683bd3

Browse files
Update teststl.cpp
1 parent 16d3369 commit 8683bd3

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

test/teststl.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TestStl : public TestFixture {
4242
TEST_CASE(outOfBoundsSymbolic);
4343
TEST_CASE(outOfBoundsIndexExpression);
4444
TEST_CASE(outOfBoundsIterator);
45+
TEST_CASE(outOfBoundsErrorPath;
4546

4647
TEST_CASE(iterator1);
4748
TEST_CASE(iterator2);
@@ -1124,6 +1125,21 @@ class TestStl : public TestFixture {
11241125
errout_str());
11251126
}
11261127

1128+
void outOfBoundsErrorPath() {
1129+
Settings s = settings;
1130+
s.templateLocation = "{file}:{line}:note:{info}";
1131+
check("int f(int i) {\n"
1132+
" std::string s = \"abc\";\n"
1133+
" if (i > 5)\n"
1134+
" return 0;\n"
1135+
" return s[i];\n"
1136+
"}\n", s);
1137+
ASSERT_EQUALS("[test.cpp:5:13]: warning: Either the condition 'i>5' is redundant or 'i' can have the value 5. Expression 's[i]' causes access out of bounds. [containerOutOfBounds]\n"
1138+
"[test.cpp:3:11]: note: Assuming that condition 'i>5' is not redundant\n"
1139+
"[test.cpp:5:13]: note: Access out of bounds\n",
1140+
errout_str());
1141+
}
1142+
11271143
void iterator1() {
11281144
check("void f()\n"
11291145
"{\n"

0 commit comments

Comments
 (0)