* Add test for #10773 * Add test for #10878 * Add test for #8991
This commit is contained in:
parent
3ca2eb984e
commit
6a914dc435
|
@ -188,6 +188,7 @@ private:
|
|||
TEST_CASE(array_index_61); // #10621
|
||||
TEST_CASE(array_index_62); // #7684
|
||||
TEST_CASE(array_index_63); // #10979
|
||||
TEST_CASE(array_index_64); // #10878
|
||||
TEST_CASE(array_index_multidim);
|
||||
TEST_CASE(array_index_switch_in_for);
|
||||
TEST_CASE(array_index_for_in_for); // FP: #2634
|
||||
|
@ -1796,6 +1797,30 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void array_index_64() // #10878
|
||||
{
|
||||
check("struct Array {\n"
|
||||
" int x[10];\n"
|
||||
" int& accessArrayRef(int a) { return x[a]; }\n"
|
||||
"};\n"
|
||||
"void f() {\n"
|
||||
" Array array = {};\n"
|
||||
" array.accessArrayRef(10);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Array 'x[10]' accessed at index 10, which is out of bounds.\n", errout.str());
|
||||
|
||||
check("int i = 10;\n"
|
||||
"struct Array {\n"
|
||||
" int x[10];\n"
|
||||
" int& accessArrayRef(int a) { return x[a]; }\n"
|
||||
"};\n"
|
||||
"void f() {\n"
|
||||
" Array array = {};\n"
|
||||
" array.accessArrayRef(i);\n"
|
||||
"}\n");
|
||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Array 'x[10]' accessed at index 10, which is out of bounds.\n", "", errout.str());
|
||||
}
|
||||
|
||||
void array_index_multidim() {
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
|
|
|
@ -227,6 +227,17 @@ private:
|
|||
" outfile << vec_points[0](0) << static_cast<int>(d) << ' ';\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f(unsigned b, int len, unsigned char rem) {\n" // #10773
|
||||
" int bits = 0;\n"
|
||||
" while (len > 8) {\n"
|
||||
" b = b >> rem;\n"
|
||||
" bits += 8 - rem;\n"
|
||||
" if (bits == 512)\n"
|
||||
" len -= 8;\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void checkIntegerOverflow() {
|
||||
|
|
|
@ -207,6 +207,7 @@ private:
|
|||
TEST_CASE(varidenum4);
|
||||
TEST_CASE(varidenum5);
|
||||
TEST_CASE(varidenum6); // #9180
|
||||
TEST_CASE(varidenum7); // #8991
|
||||
|
||||
TEST_CASE(varidnamespace1);
|
||||
TEST_CASE(varidnamespace2);
|
||||
|
@ -3353,6 +3354,20 @@ private:
|
|||
ASSERT_EQUALS(expected, tokenize(code));
|
||||
}
|
||||
|
||||
void varidenum7() { // #8991
|
||||
const char code[] = "namespace N1 { const int c = 42; }\n"
|
||||
"namespace N2 { const int c = 24; }\n"
|
||||
"struct S {\n"
|
||||
" enum { v1 = N1::c, v2 = N2::c };\n"
|
||||
"};\n";
|
||||
const char expected[] = "1: namespace N1 { const int c@1 = 42 ; }\n"
|
||||
"2: namespace N2 { const int c@2 = 24 ; }\n"
|
||||
"3: struct S {\n"
|
||||
"4: enum Anonymous0 { v1 = N1 :: c@1 , v2 = N2 :: c@2 } ;\n"
|
||||
"5: } ;\n";
|
||||
ASSERT_EQUALS(expected, tokenize(code));
|
||||
}
|
||||
|
||||
void varid_classnameshaddowsvariablename() {
|
||||
const char code[] = "class Data;\n"
|
||||
"void strange_declarated(const Data& Data);\n"
|
||||
|
|
Loading…
Reference in New Issue