* Add tests for #6925, #11042, #11494

* Format
This commit is contained in:
chrchr-github 2023-04-19 21:19:45 +02:00 committed by GitHub
parent 31e714cded
commit 938ad990f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

View File

@ -5250,6 +5250,16 @@ private:
" g(a);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
ctu("const int a[1] = { 1 };\n" // #11042
"void g(const int* d) {\n"
" (void)d[2];\n"
"}\n"
"void f() {\n"
" g(a);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:3]: (error) Array index out of bounds; 'd' buffer size is 4 and it is accessed at offset 8.\n",
errout.str());
}
void ctu_variable() {

View File

@ -3213,8 +3213,8 @@ private:
tok(code));
}
void simplifyTypedef140() { // #10798
{
void simplifyTypedef140() {
{ // #10798
const char code[] = "typedef void (*b)();\n"
"enum class E { a, b, c };\n";
ASSERT_EQUALS("enum class E { a , b , c } ;", tok(code));
@ -3224,6 +3224,11 @@ private:
"enum class E { A };\n";
ASSERT_EQUALS("enum class E { A } ;", tok(code));
}
{ // #11494
const char code[] = "typedef struct S {} KEY;\n"
"class C { enum E { KEY }; };\n";
ASSERT_EQUALS("struct S { } ; class C { enum E { KEY } ; } ;", tok(code));
}
}
void simplifyTypedef141() { // #10144

View File

@ -4750,6 +4750,15 @@ private:
" return true;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #6925
check("void f(const std::string& s, std::string::iterator i) {\n"
" if (i != s.end() && *(i + 1) == *i) {\n"
" if (i + 1 != s.end()) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n",
errout.str());
}
void dereferenceInvalidIterator2() {