https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113916
Bug ID: 113916 Summary: gcc allows overriding a non-deleted private base class dtor with a deleted defaulted dtor Product: gcc Version: 13.2.0 Status: UNCONFIRMED Keywords: accepts-invalid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rush102333 at gmail dot com Target Milestone: --- The following code seems invaild, because when the base class dtor is private, it's natural that the explicitly defaulted derived class dtor should be defined as deleted since it can't be defined as anything else. Then the question comes that you can't override a non-deleted function(the virtual, though inaccessible, base class dtor) with a deleted function(the explicitly defaulted and implicitly deleted derived dtor). Actually, we've confirmed that Clang rejects it. But it works well in gcc_13.2.0. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class Base { virtual ~Base() = default; }; class Derived : public Base { ~Derived() override = default; }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We're not sure but we tend to believe that it would more likely be a bug of gcc. Clang 17.0.1 rejects the code by complaining that: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <source>:8:5: warning: explicitly defaulted destructor is implicitly deleted [-Wdefaulted-function-deleted] 8 | ~Derived() override = default; | ^ <source>:6:17: note: destructor of 'Derived' is implicitly deleted because base class 'Base' has an inaccessible destructor 6 | class Derived : public Base | ^ <source>:8:27: note: replace 'default' with 'delete' 8 | ~Derived() override = default; | ^~~~~~~ | delete <source>:8:5: error: deleted function '~Derived' cannot override a non-deleted function 8 | ~Derived() override = default; | ^ <source>:3:13: note: overridden virtual function is here 3 | virtual ~Base() = default; | ^ <source>:6:17: note: destructor of 'Derived' is implicitly deleted because base class 'Base' has an inaccessible destructor 6 | class Derived : public Base | ^ 1 warning and 1 error generated. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Please check https://godbolt.org/z/4Tvc9Tfsz