Skip to content

Commit c6ae9ae

Browse files
Fix #12619 FP unusedPrivateFunction with trailing return type and override (#6299)
1 parent 8cd680b commit c6ae9ae

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

lib/symboldatabase.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,9 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
19591959
}
19601960

19611961
// skip over trailing return type
1962+
bool hasTrailingRet = false;
19621963
if (tok2 && tok2->str() == ".") {
1964+
hasTrailingRet = true;
19631965
for (tok2 = tok2->next(); tok2; tok2 = tok2->next()) {
19641966
if (Token::Match(tok2, ";|{|=|override|final"))
19651967
break;
@@ -2030,7 +2032,8 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
20302032
(tok2->isUpperCaseName() && Token::Match(tok2, "%name% (") && tok2->next()->link()->strAt(1) == "{") ||
20312033
Token::Match(tok2, ": ::| %name% (|::|<|{") ||
20322034
Token::Match(tok2, "&|&&| ;|{") ||
2033-
Token::Match(tok2, "= delete|default ;"))) {
2035+
Token::Match(tok2, "= delete|default ;") ||
2036+
(hasTrailingRet && Token::Match(tok2, "final|override")))) {
20342037
funcStart = tok;
20352038
argStart = tok->next();
20362039
declEnd = Token::findmatch(tok2, "{|;");

test/testunusedprivfunc.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class TestUnusedPrivateFunction : public TestFixture {
8383

8484
TEST_CASE(templateSimplification); //ticket #6183
8585
TEST_CASE(maybeUnused);
86+
TEST_CASE(trailingReturn);
8687
}
8788

8889
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
@@ -863,6 +864,18 @@ class TestUnusedPrivateFunction : public TestFixture {
863864
"};");
864865
ASSERT_EQUALS("", errout_str());
865866
}
867+
868+
void trailingReturn() {
869+
check("struct B { virtual void f(); };\n"
870+
"struct D : B {\n"
871+
" auto f() -> void override;\n"
872+
"private:\n"
873+
" auto g() -> void;\n"
874+
"};\n"
875+
"auto D::f() -> void { g(); }\n"
876+
"auto D::g() -> void {}\n");
877+
ASSERT_EQUALS("", errout_str());
878+
}
866879
};
867880

868881
REGISTER_TEST(TestUnusedPrivateFunction)

0 commit comments

Comments
 (0)