Skip to content

Commit

Permalink
Fix #12619 FP unusedPrivateFunction with trailing return type and ove…
Browse files Browse the repository at this point in the history
…rride
  • Loading branch information
chrchr-github committed Apr 16, 2024
1 parent 646f869 commit 32d90d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1959,7 +1959,9 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
}

// skip over trailing return type
bool hasTrailingRet = false;
if (tok2 && tok2->str() == ".") {
hasTrailingRet = true;
for (tok2 = tok2->next(); tok2; tok2 = tok2->next()) {
if (Token::Match(tok2, ";|{|=|override|final"))
break;
Expand Down Expand Up @@ -2030,7 +2032,8 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
(tok2->isUpperCaseName() && Token::Match(tok2, "%name% (") && tok2->next()->link()->strAt(1) == "{") ||
Token::Match(tok2, ": ::| %name% (|::|<|{") ||
Token::Match(tok2, "&|&&| ;|{") ||
Token::Match(tok2, "= delete|default ;"))) {
Token::Match(tok2, "= delete|default ;") ||
(hasTrailingRet && Token::Match(tok2, "final|override")))) {
*funcStart = tok;
*argStart = tok->next();
*declEnd = Token::findmatch(tok2, "{|;");
Expand Down
13 changes: 13 additions & 0 deletions test/testunusedprivfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class TestUnusedPrivateFunction : public TestFixture {

TEST_CASE(templateSimplification); //ticket #6183
TEST_CASE(maybeUnused);
TEST_CASE(trailingReturn);
}

#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
Expand Down Expand Up @@ -863,6 +864,18 @@ class TestUnusedPrivateFunction : public TestFixture {
"};");
ASSERT_EQUALS("", errout_str());
}

void trailingReturn() {
check("struct B { virtual void f(); };\n"
"struct D : B {\n"
" auto f() -> void override;\n"
"private:\n"
" auto g() -> void;\n"
"};\n"
"auto D::f() -> void { g(); }\n"
"auto D::g() -> void {}\n");
ASSERT_EQUALS("", errout_str());
}
};

REGISTER_TEST(TestUnusedPrivateFunction)

0 comments on commit 32d90d6

Please sign in to comment.