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

            Bug ID: 115938
           Summary: gcc allows inheriting base class with private
                    destructor during virtual inheritance
           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 is accepted by the latest version of GCC but rejected by
clang, MSVC and EDG:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class A
{
 protected:
  virtual ~A(){};
};

class B : virtual A
{
 public:
  virtual ~B(){};
};

class C:B
{
public:
    ~C(){};
};

C c;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The code seems to be invalid. Because class "B" private inherits "A" ,the dtor
of "A" should be private in "B" and cannot be accessed in "C". When it's not
under a virtual inheritance case, the problem does not exist.

Please check https://godbolt.org/z/jd71dWKfs

Reply via email to