implicitly-defined virtual destructors

Mark Mitchell mark at codesourcery.com
Fri Aug 2 00:20:59 UTC 2002



--On Thursday, August 01, 2002 05:14:03 PM -0700 Jessica Han 
<jessica at cup.hp.com> wrote:

>
> For test case test.C
> class base_class
> {
>  public:
>  virtual ~base_class(){};
> };
>
> class derived_class :public base_class{
> public:
>  virtual void foo(){};
> };
>
> int main(){
>  derived_class B;
>  base_class A;
> }
> ABI says "If a class has an implicitly-defined virtual destructor, its
> entries come after the declared virtual function pointers. " Thus in
> vtable of derived_class, function descriptor of the implicitly-defined
> virtual destructors derived_class::~derived_class should come after
> derived_class::foo().
> But gcc generates the following vtable for derived_class:
> vtable for derived_class:
>         data4   0
>         data4   0
>         data4   typeinfo for derived_class#
>         data4   0
>         data8.ua @iplt(derived_class::~derived_class [in-charge]()#)
>         data8.ua 0
>         data8.ua @iplt(derived_class::~derived_class [in-charge
> deleting]()#)
>         data8.ua 0
>         data8.ua @iplt(derived_class::foo()#)
>         data8.ua 0
>
> Does this violate the ABI? If this is not a test case for
> implicitly-defined virtual destructors, could you please tell me how
> should I modify my test case? Thanks.

GCC puts the destructor first because base_class is the primary base
for derived_class; see the section on vtable layout for an explanation
of how that works.  If you do this:

  struct A { virtual void f(); };
  struct B { virtual ~B(); };
  struct C : public A, public B { B b; };

you should see that C's vtable has "A::f" followed by "C::~C".

-- 
Mark Mitchell                mark at codesourcery.com
CodeSourcery, LLC            http://www.codesourcery.com



More information about the cxx-abi-dev mailing list