From f303757b1d3fcb19febb35ec45f0c1d1f78dcbe6 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 23 Feb 2024 08:20:39 +0100 Subject: [PATCH] Fix #12439 Destructors missing 'overriddenFunction' when they are overriden (#6001) --- lib/symboldatabase.cpp | 8 ++++++++ test/testclass.cpp | 9 +++++++++ 2 files changed, 17 insertions(+) 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() {