Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

no base classes of the same type as the first non-static data member

16 views
Skip to first unread message

David Krauss

unread,
May 15, 2010, 10:18:53 PM5/15/10
to
Is the last requirement of standard-layout classes, 9/6, necessary?

A footnote explanation is provided:

This ensures that two subobjects that have the same class type and
that belong to the same most-derived object are not allocated at the
same address (5.10).

Taken alone, the footnote is incorrect. Two empty base classes with a
common base class must produce two instances of the base class at the
same address.

struct A {};
struct B : A {};
struct C : A {};
struct D : B, C {};

D d;
static_cast<A*>(static_cast<B*>(&d))
== static_cast<A*>(static_cast<C*>(&d)); // required

Taken in the context of 5.10, subobjects are only mentioned in the
comparison requirements of pointers to members. Base subobjects are
irrelevant.

There wasn't such a restriction in C++03. Moreover, it doesn't make
sense to give special status to comparison between a pointer to a
member subobject and a pointer to a base subobject above that of
comparison between pointers to base subobjects.

Even if there is an ABI out there that requires every member to be
allocated at a different address from any base of the same type, yet
already allows the empty base class optimization on the above code, I
think the ABI is buggy and the standard shouldn't capture this.

The language goes back to N2172
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2172.html#Revision-history
which suggests that multiple inheritance might cause trouble and need
to be disallowed to provide ABI compatibility
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2172.html#ABI
however, that was ultimately allowed and in that light the requirement
doesn't make sense.

--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

0 new messages