Fix #10091 FP shadowFunction with default destructor implementation / Tests for #8635, #9776, #9940, #9951, #10018 (#3763)

This commit is contained in:
chrchr-github 2022-02-02 19:30:49 +01:00 committed by GitHub
parent 69ee464dff
commit dad64bfcc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 3 deletions

View File

@ -639,7 +639,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
} }
// function prototype? // function prototype?
else if (declEnd && declEnd->str() == ";") { else if (declEnd && declEnd->str() == ";") {
if (tok->previous() && tok->previous()->str() == "::" && if (tok->astParent() && tok->astParent()->str() == "::" &&
Token::Match(declEnd->previous(), "default|delete")) { Token::Match(declEnd->previous(), "default|delete")) {
addClassFunction(&scope, &tok, argStart); addClassFunction(&scope, &tok, argStart);
continue; continue;

View File

@ -268,6 +268,15 @@ void * memleak_mmap2() // #8327
return NULL; return NULL;
} }
void * identicalCondition_mmap(int fd, size_t size) // #9940
{
void* buffer = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (buffer == MAP_FAILED) {
return NULL;
}
return buffer;
}
void resourceLeak_fdopen(int fd) void resourceLeak_fdopen(int fd)
{ {
// cppcheck-suppress unreadVariable // cppcheck-suppress unreadVariable

View File

@ -144,6 +144,15 @@ private:
" Array a = f();\n" " Array a = f();\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("struct S {\n" // #9951
" enum E { E0 };\n"
" std::array<double, 1> g(S::E);\n"
"};\n"
"void f() {\n"
" std::array<double, 1> a = S::g(S::E::E0);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void structmember() { void structmember() {

View File

@ -381,6 +381,9 @@ private:
check("void f1(int x) { x; }", true); check("void f1(int x) { x; }", true);
ASSERT_EQUALS("[test.cpp:1]: (warning) Unused variable value 'x'\n", errout.str()); ASSERT_EQUALS("[test.cpp:1]: (warning) Unused variable value 'x'\n", errout.str());
check("void f() { if (Type t; g(t)) {} }"); // #9776
ASSERT_EQUALS("", errout.str());
} }
void vardecl() { void vardecl() {

View File

@ -708,13 +708,23 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'ptr' after it is deallocated / released\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'ptr' after it is deallocated / released\n", errout.str());
} }
void deallocuse9() { // #9781 void deallocuse9() {
check("void f(Type* p) {\n" check("void f(Type* p) {\n" // #9781
" std::shared_ptr<Type> sp(p);\n" " std::shared_ptr<Type> sp(p);\n"
" bool b = p->foo();\n" " bool b = p->foo();\n"
" return b;\n" " return b;\n"
"}\n", /*cpp*/ true); "}\n", /*cpp*/ true);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("struct A {\n" // #8635
" std::vector<std::unique_ptr<A>> array_;\n"
" A* foo() {\n"
" A* a = new A();\n"
" array_.push_back(std::unique_ptr<A>(a));\n"
" return a;\n"
" }\n"
"};\n", /*cpp*/ true);
ASSERT_EQUALS("", errout.str());
} }
void doublefree1() { // #3895 void doublefree1() { // #3895

View File

@ -2693,6 +2693,16 @@ private:
" if (addr == &x->y.z[0]) {}\n" " if (addr == &x->y.z[0]) {}\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkP("typedef int Count;\n" // #10018
"#define offsetof(TYPE, MEMBER) ((Count) & ((TYPE*)0)->MEMBER)\n"
"struct S {\n"
" int a[20];\n"
"};\n"
"int g(int i) {\n"
" return offsetof(S, a[i]);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void nullpointerSwitch() { // #2626 void nullpointerSwitch() { // #2626

View File

@ -9336,6 +9336,15 @@ private:
check("class C { C(); void foo() { static int C = 0; } }"); // #9195 - shadow constructor check("class C { C(); void foo() { static int C = 0; } }"); // #9195 - shadow constructor
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("struct C {\n" // #10091 - shadow destructor
" ~C();\n"
" void f() {\n"
" bool C{};\n"
" }\n"
"};\n"
"C::~C() = default;");
ASSERT_EQUALS("", errout.str());
// 10752 - no // 10752 - no
check("struct S {\n" check("struct S {\n"
" int i;\n" " int i;\n"