Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ static bool checkFunctionUsage(const Function *privfunc, const Scope* scope)

for (const Variable &var : scope->varlist) {
if (var.isStatic()) {
const Token* tok = Token::findmatch(scope->bodyEnd, "%varid% =|(|{", var.declarationId());
const Token* tok = Token::findmatch(scope->bodyStart, "%varid% =|(|{", var.declarationId());
if (tok)
tok = tok->tokAt(2);
while (tok && tok->str() != ";") {
Expand Down
11 changes: 8 additions & 3 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,15 +1081,15 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass)

// Set function call pointers
for (const Token* tok = mTokenizer->list.front(); tok != mTokenizer->list.back(); tok = tok->next()) {
if (tok->isName() && !tok->function() && tok->varId() == 0 && Token::Match(tok, "%name% [(,)>]") && !isReservedName(tok->str())) {
if (tok->isName() && !tok->function() && tok->varId() == 0 && Token::Match(tok, "%name% [(,)>;]") && !isReservedName(tok->str())) {
if (tok->next()->str() == ">" && !tok->next()->link())
continue;

if (tok->next()->str() != "(") {
const Token *start = tok;
while (Token::Match(start->tokAt(-2), "%name% ::"))
start = start->tokAt(-2);
if (!Token::Match(start->previous(), "[(,<]") && !Token::Match(start->tokAt(-2), "[(,<] &"))
if (!Token::Match(start->previous(), "[(,<=]") && !Token::Match(start->tokAt(-2), "[(,<=] &") && !Token::Match(start, "%name% ;"))
continue;
}

Expand Down Expand Up @@ -5352,8 +5352,13 @@ const Function* SymbolDatabase::findFunction(const Token *tok) const
else
tok1 = nullptr;

if (tok1)
if (tok1) {
const Function* func = currScope->findFunction(tok1);
if (func)
return func;

currScope = currScope->findRecordInNestedList(tok1->str());
}
}

if (tok1)
Expand Down
27 changes: 27 additions & 0 deletions test/testunusedprivfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class TestUnusedPrivateFunction : public TestFixture {
TEST_CASE(func_pointer4); // ticket #2807
TEST_CASE(func_pointer5); // ticket #2233
TEST_CASE(func_pointer6); // ticket #4787
TEST_CASE(func_pointer7); // ticket #10516

TEST_CASE(ctor);
TEST_CASE(ctor2);
Expand Down Expand Up @@ -349,6 +350,32 @@ class TestUnusedPrivateFunction : public TestFixture {
ASSERT_EQUALS("", errout.str());
}

void func_pointer7() { // #10516
check("class C {\n"
" static void f() {}\n"
" static constexpr void(*p)() = f;\n"
"};\n");
ASSERT_EQUALS("", errout.str());

check("class C {\n"
" static void f() {}\n"
" static constexpr void(*p)() = &f;\n"
"};\n");
ASSERT_EQUALS("", errout.str());

check("class C {\n"
" static void f() {}\n"
" static constexpr void(*p)() = C::f;\n"
"};\n");
ASSERT_EQUALS("", errout.str());

check("class C {\n"
" static void f() {}\n"
" static constexpr void(*p)() = &C::f;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}


void ctor() {
check("class PrivateCtor\n"
Expand Down