Skip to content
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
}
// function prototype?
else if (declEnd && declEnd->str() == ";") {
if (tok->previous() && tok->previous()->str() == "::" &&
if (tok->astParent() && tok->astParent()->str() == "::" &&
Token::Match(declEnd->previous(), "default|delete")) {
addClassFunction(&scope, &tok, argStart);
continue;
Expand Down
9 changes: 9 additions & 0 deletions test/cfg/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ void * memleak_mmap2() // #8327
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)
{
// cppcheck-suppress unreadVariable
Expand Down
9 changes: 9 additions & 0 deletions test/test64bit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ class Test64BitPortability : public TestFixture {
" Array a = f();\n"
"}");
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() {
Expand Down
3 changes: 3 additions & 0 deletions test/testincompletestatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ class TestIncompleteStatement : public TestFixture {
check("void f1(int x) { x; }", true);
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() {
Expand Down
14 changes: 12 additions & 2 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,13 +708,23 @@ class TestLeakAutoVar : public TestFixture {
ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'ptr' after it is deallocated / released\n", errout.str());
}

void deallocuse9() { // #9781
check("void f(Type* p) {\n"
void deallocuse9() {
check("void f(Type* p) {\n" // #9781
" std::shared_ptr<Type> sp(p);\n"
" bool b = p->foo();\n"
" return b;\n"
"}\n", /*cpp*/ true);
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
Expand Down
10 changes: 10 additions & 0 deletions test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2693,6 +2693,16 @@ class TestNullPointer : public TestFixture {
" if (addr == &x->y.z[0]) {}\n"
"}");
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
Expand Down
9 changes: 9 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9324,6 +9324,15 @@ class TestOther : public TestFixture {
check("class C { C(); void foo() { static int C = 0; } }"); // #9195 - shadow constructor
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
check("struct S {\n"
" int i;\n"
Expand Down