diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 7d04aebbc23..80039b2af59 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4709,6 +4709,14 @@ const Function * Function::getOverriddenFunctionRecursive(const ::Type* baseType } } + if (isDestructor()) { + auto it = std::find_if(parent->functionList.begin(), parent->functionList.end(), [](const Function& f) { + return f.isDestructor() && f.isImplicitlyVirtual(); + }); + if (it != parent->functionList.end()) + return &*it; + } + if (!derivedFromType->derivedFrom.empty() && !derivedFromType->hasCircularDependencies() && !isDerivedFromItself(baseType->classScope->className, i.name)) { // avoid endless recursion, see #5289 Crash: Stack overflow in isImplicitlyVirtual_rec when checking SVN and // #5590 with a loop within the class hierarchy. diff --git a/test/testclass.cpp b/test/testclass.cpp index 5938170a1f5..f0ffab38135 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -8558,6 +8558,15 @@ class TestClass : public TestFixture { " }\n" "};\n"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier.\n", errout.str()); + + checkOverride("struct S {\n" // #12439 + " virtual ~S() = default;\n" + "};\n" + "struct D : S {\n" + " ~D() {}\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier.\n", + errout.str()); } void overrideCVRefQualifiers() {