Skip to content

Commit dad64bf

Browse files
Fix #10091 FP shadowFunction with default destructor implementation / Tests for #8635, #9776, #9940, #9951, #10018 (danmar#3763)
1 parent 69ee464 commit dad64bf

File tree

7 files changed

+53
-3
lines changed

7 files changed

+53
-3
lines changed

lib/symboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
639639
}
640640
// function prototype?
641641
else if (declEnd && declEnd->str() == ";") {
642-
if (tok->previous() && tok->previous()->str() == "::" &&
642+
if (tok->astParent() && tok->astParent()->str() == "::" &&
643643
Token::Match(declEnd->previous(), "default|delete")) {
644644
addClassFunction(&scope, &tok, argStart);
645645
continue;

test/cfg/posix.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,15 @@ void * memleak_mmap2() // #8327
268268
return NULL;
269269
}
270270

271+
void * identicalCondition_mmap(int fd, size_t size) // #9940
272+
{
273+
void* buffer = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
274+
if (buffer == MAP_FAILED) {
275+
return NULL;
276+
}
277+
return buffer;
278+
}
279+
271280
void resourceLeak_fdopen(int fd)
272281
{
273282
// cppcheck-suppress unreadVariable

test/test64bit.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ class Test64BitPortability : public TestFixture {
144144
" Array a = f();\n"
145145
"}");
146146
ASSERT_EQUALS("", errout.str());
147+
148+
check("struct S {\n" // #9951
149+
" enum E { E0 };\n"
150+
" std::array<double, 1> g(S::E);\n"
151+
"};\n"
152+
"void f() {\n"
153+
" std::array<double, 1> a = S::g(S::E::E0);\n"
154+
"}\n");
155+
ASSERT_EQUALS("", errout.str());
147156
}
148157

149158
void structmember() {

test/testincompletestatement.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ class TestIncompleteStatement : public TestFixture {
381381
check("void f1(int x) { x; }", true);
382382
ASSERT_EQUALS("[test.cpp:1]: (warning) Unused variable value 'x'\n", errout.str());
383383

384+
check("void f() { if (Type t; g(t)) {} }"); // #9776
385+
ASSERT_EQUALS("", errout.str());
386+
384387
}
385388

386389
void vardecl() {

test/testleakautovar.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,13 +708,23 @@ class TestLeakAutoVar : public TestFixture {
708708
ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'ptr' after it is deallocated / released\n", errout.str());
709709
}
710710

711-
void deallocuse9() { // #9781
712-
check("void f(Type* p) {\n"
711+
void deallocuse9() {
712+
check("void f(Type* p) {\n" // #9781
713713
" std::shared_ptr<Type> sp(p);\n"
714714
" bool b = p->foo();\n"
715715
" return b;\n"
716716
"}\n", /*cpp*/ true);
717717
ASSERT_EQUALS("", errout.str());
718+
719+
check("struct A {\n" // #8635
720+
" std::vector<std::unique_ptr<A>> array_;\n"
721+
" A* foo() {\n"
722+
" A* a = new A();\n"
723+
" array_.push_back(std::unique_ptr<A>(a));\n"
724+
" return a;\n"
725+
" }\n"
726+
"};\n", /*cpp*/ true);
727+
ASSERT_EQUALS("", errout.str());
718728
}
719729

720730
void doublefree1() { // #3895

test/testnullpointer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,6 +2693,16 @@ class TestNullPointer : public TestFixture {
26932693
" if (addr == &x->y.z[0]) {}\n"
26942694
"}");
26952695
ASSERT_EQUALS("", errout.str());
2696+
2697+
checkP("typedef int Count;\n" // #10018
2698+
"#define offsetof(TYPE, MEMBER) ((Count) & ((TYPE*)0)->MEMBER)\n"
2699+
"struct S {\n"
2700+
" int a[20];\n"
2701+
"};\n"
2702+
"int g(int i) {\n"
2703+
" return offsetof(S, a[i]);\n"
2704+
"}\n");
2705+
ASSERT_EQUALS("", errout.str());
26962706
}
26972707

26982708
void nullpointerSwitch() { // #2626

test/testother.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9336,6 +9336,15 @@ class TestOther : public TestFixture {
93369336
check("class C { C(); void foo() { static int C = 0; } }"); // #9195 - shadow constructor
93379337
ASSERT_EQUALS("", errout.str());
93389338

9339+
check("struct C {\n" // #10091 - shadow destructor
9340+
" ~C();\n"
9341+
" void f() {\n"
9342+
" bool C{};\n"
9343+
" }\n"
9344+
"};\n"
9345+
"C::~C() = default;");
9346+
ASSERT_EQUALS("", errout.str());
9347+
93399348
// 10752 - no
93409349
check("struct S {\n"
93419350
" int i;\n"

0 commit comments

Comments
 (0)