Class layout algorithm

Mark Mitchell mark at codesourcery.com
Wed Dec 29 08:24:29 UTC 1999


The class layout algorithm in the "Non_POD Class Types" section of the
ABI layout document seems to me to rather unclear with respect to
virtual base classes.

In particular, a literal reading of the "Data Layout" document would
seem to imply that given:

  class A { int i; };
  class B : virtual public A { int j; };
  class C : virtual public A { int k; };
  class D : public B, public C { int l; };

an object of class `D' would look like:

  j
  i
  k
  i
  l

In particular, there would be two copies of `A' in `D'.

Something in the description needs to indicate that when allocating
bases, one allocates only enough space for the portion of the base
that does not include virtual base classes, i.e., `sizeof (D)' after
step II, but before step III.  And, the section on "Virtual Base
Allocation" needs to indicate that indirect (as well as direct)
virtual bases are allocated in that step.

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




More information about the cxx-abi-dev mailing list