public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113916] New: gcc allows overriding a non-deleted private base class dtor with a deleted defaulted dtor
@ 2024-02-14  7:51 rush102333 at gmail dot com
  2024-02-15  0:23 ` [Bug c++/113916] gcc allows overriding a non-deleted private base class dtor with a " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: rush102333 at gmail dot com @ 2024-02-14  7:51 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/113916] gcc allows overriding a non-deleted private base class dtor with a defaulted dtor
  2024-02-14  7:51 [Bug c++/113916] New: gcc allows overriding a non-deleted private base class dtor with a deleted defaulted dtor rush102333 at gmail dot com
@ 2024-02-15  0:23 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-15  0:23 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
            Summary|gcc allows overriding a     |gcc allows overriding a
                   |non-deleted private base    |non-deleted private base
                   |class dtor with a deleted   |class dtor with a defaulted
                   |defaulted dtor              |dtor
   Last reconfirmed|                            |2024-02-15
             Status|UNCONFIRMED                 |NEW
      Known to fail|                            |4.4.7, 4.7.1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

Looks not to be a regression either.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-15  0:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-14  7:51 [Bug c++/113916] New: gcc allows overriding a non-deleted private base class dtor with a deleted defaulted dtor rush102333 at gmail dot com
2024-02-15  0:23 ` [Bug c++/113916] gcc allows overriding a non-deleted private base class dtor with a " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).