Class layout algorithm

Jim Dehnert dehnert at baalbek.engr.sgi.com
Wed Dec 29 19:56:53 UTC 1999


I'll fix these.  I believe your interpretation of the intent is correct.
I believe, too, that the intent was to allocate the (indirect) virtual
base classes in depth-first rather than breadth-first order.  Correct?

But they raise another interesting point.  What if the only non-vptr
data in a class comes from virtual base classes?  Then it seems that we
could treat it as a "nearly empty" class for purposes of being a
primary base class (which I think is the only use of the concept).

Now that I look at it, there's another question.  Virtual base classes
that are primary base classes of some non-virtual base class (direct or
indirect) are inherently allocated (vptr only, I trust, since they
should be nearly empty, modulo the above question) as part of that base
class.  I suggest that we use the first such occurrence (depth-first
again) as the allocation of the virtual base rather than doing it again.
(Again, this may have been the intent, but it isn't stated that I see.)

I will open both of these questions as issues (but make Mark's
suggested changes without one).  I will also attempt the changes
suggested by the questions as a draft proposal.  If you see problems,
let me know ASAP...

> From: Mark Mitchell <mark at codesourcery.com>
> 
> 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.

-	    Jim Dehnert		dehnert at sgi.com
				(650)933-4272




More information about the cxx-abi-dev mailing list