Skip to content

Commit b7b92b2

Browse files
committed
Fixed danmar#6674 (false positive 'unusedPrivateFunction' - calling virtual function in subclass)
1 parent c23c1f2 commit b7b92b2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/symboldatabase.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2789,7 +2789,9 @@ bool Function::isImplicitlyVirtual_rec(const ::Type* baseType, bool& safe) const
27892789

27902790
// check for matching return parameters
27912791
while (temp1->str() != "virtual") {
2792-
if (temp1->str() != temp2->str()) {
2792+
if (temp1->str() != temp2->str() &&
2793+
!(temp1->str() == derivedFromType->name() &&
2794+
temp2->str() == baseType->name())) {
27932795
returnMatch = false;
27942796
break;
27952797
}

test/testunusedprivfunc.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,24 @@ class TestUnusedPrivateFunction : public TestFixture {
481481
" void func() {}\n"
482482
"};");
483483
ASSERT_EQUALS("", errout.str());
484+
485+
check("class Base {\n"
486+
"public:\n"
487+
" void dostuff() {\n"
488+
" f();\n"
489+
" }\n"
490+
"\n"
491+
"private:\n"
492+
" virtual Base* f() = 0;\n"
493+
"};\n"
494+
"\n"
495+
"class Derived : public Base {\n"
496+
"private:\n"
497+
" Derived* f() {\n"
498+
" return 0;\n"
499+
" }\n"
500+
"};");
501+
ASSERT_EQUALS("", errout.str());
484502
}
485503

486504
void friendClass() {

0 commit comments

Comments
 (0)