https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90790

            Bug ID: 90790
           Summary: Using override on a private overridden destructor
                    shall produce an error
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follows:

This code:

class Base
{
    virtual ~Base() = default;
};

class Derived : public Base
{
    ~Derived() override = default;
};

My gcc is 10.0.0, and it accepts the code. clang++ rejects its with the
message:

<source>:8:2: error: deleted function '~Derived' cannot override a non-deleted
function

 ~Derived() override = default;

 ^

<source>:3:10: note: overridden virtual function is here

 virtual ~Base() = default;

         ^

<source>:6:17: note: destructor of 'Derived' is implicitly deleted because base
class 'Base' has an inaccessible destructor

class Derived : public Base

                ^

<source>:8:2: warning: explicitly defaulted destructor is implicitly deleted
[-Wdefaulted-function-deleted]

 ~Derived() override = default;

 ^

<source>:6:17: note: destructor of 'Derived' is implicitly deleted because base
class 'Base' has an inaccessible destructor

class Derived : public Base

                ^

1 warning and 1 error generated.

Compiler returned: 1

msvc also rejects the code:

source>(9): warning C4624: 'Derived': destructor was implicitly defined as
deleted

<source>(8): error C2282: 'Derived::~Derived' cannot override 'Base::~Base'

<source>(3): note: 'Base::~Base' is not deleted

The code sample comes from https://bugs.llvm.org/show_bug.cgi?id=30844

David Blaikie makes a comments: Because the base class dtor is private, the
explicitly defaulted derived class dtor is defined as deleted (since it can't
be defined as anything else - because the base class dtor is inaccessible for
it to access, so the derived dtor can't be implemented).

His argument seems to be correct.

Reply via email to