* Add test for #6541, avoid duplicate warning

* Add test for #5475

* Fix test

* Merge

* Add test for #8666

* Fix #11239 checkLibraryCheckType with asm goto() (invalid varid)

* Format

* Add tests for #1201, #2654

* Fix test

* Add test for #6379
This commit is contained in:
chrchr-github 2022-09-29 07:05:29 +02:00 committed by GitHub
parent 441f9b9509
commit 32c7b919ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View File

@ -5395,6 +5395,21 @@ private:
" return p[10];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("struct X {\n" // #2654
" int a;\n"
" char b;\n"
"};\n"
"void f() {\n"
" X s;\n"
" int* y = &s.a;\n"
" (void)y[0];\n"
" (void)y[1];\n"
" (void)y[2];\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (error) The address of local variable 'a' is accessed at non-zero index.\n"
"[test.cpp:7] -> [test.cpp:10]: (error) The address of local variable 'a' is accessed at non-zero index.\n",
errout.str());
}
void checkPipeParameterSize() { // #3521

View File

@ -8382,6 +8382,15 @@ private:
" *reg = 34;\n"
"}");
ASSERT_EQUALS("test.cpp:2:style:C-style pointer casting\n", errout.str());
check("void f(std::map<int, int>& m, int key, int value) {\n" // #6379
" m[key] = value;\n"
" m[key] = value;\n"
"}\n");
ASSERT_EQUALS("test.cpp:3:style:Variable 'm[key]' is reassigned a value before the old one has been used.\n"
"test.cpp:2:note:m[key] is assigned\n"
"test.cpp:3:note:m[key] is overwritten\n",
errout.str());
}
void redundantVarAssignment_trivial() {

View File

@ -5871,6 +5871,14 @@ private:
true);
ASSERT_EQUALS("[test.cpp:3]: (style) Using sort with iterator 'v.begin()' that is always empty.\n", errout.str());
check("void f() {\n" // #1201
" std::vector<int> v1{ 0, 1 };\n"
" std::vector<int> v2;\n"
" std::copy(v1.begin(), v1.end(), v2.begin());\n"
"}\n",
true);
ASSERT_EQUALS("[test.cpp:4]: (style) Using copy with iterator 'v2.begin()' that is always empty.\n", errout.str());
check("void f() {\n"
" std::vector<int> v;\n"
" v.insert(v.end(), 1);\n"