Virtual base allocation question

Nelson, Clark clark.nelson at intel.com
Sat Oct 13 00:35:42 UTC 2001


Consider the following case:

struct S { virtual void s(void) {} };
struct T : virtual public S { virtual void t(void) {} };
struct W : virtual public S { virtual void w(void) {} };
struct Y : virtual public T, public W {
  virtual void x(void) {}
};

S is T's primary base class, because it's nearly empty. For the same reason,
S is W's primary base class.

W is Y's primary base class, because it's dynamic and non-virtual. Because T
is not Y's primary base class, it is allocated as a virtual base class.

The question is, what is the offset of S in Y? Y actually contains 2
sub-objects of type S, one each in sub-objects of type T and W. But
according to the language rules, S is not an ambiguous base of Y, so
conversion from Y* to S* is well-formed. Then what's the value of the
result?

Needless to say, this isn't a problem for other object models with which I'm
familiar, in which virtual base allocation doesn't have exceptions for
sharing of virtual pointers with virtual bases.

--
Clark Nelson
Intel Corporation
clark.nelson at intel.com
 



More information about the cxx-abi-dev mailing list