[cxx-abi-dev] broken definition of "empty class"

Richard Smith richardsmith at google.com
Fri Oct 7 17:41:34 UTC 2016


We define "empty class" as follows:

  "A class with no non-static data members other than zero-width bitfields,
no virtual functions, no virtual base classes, and no non-empty non-virtual
proper base classes."

But this doesn't make sense: zero-width bitfields must be unnamed and
unnamed bitfields are not members, so there is no such thing as a
non-static data member that is a zero-width bitfield. (The same error
exists in the definition of "nearly empty class".)

There is implementation divergence on a case like this:

  struct A { int : 3; };
  struct B : A { int n; };

This type has size 4 in Clang and size 8 in GCC; Clang takes the rule
literally, and GCC applies a rule like:

  "A class with no non-static data members, no unnamed bitfields other than
zero-width bitfields, no virtual functions, no virtual base classes, and no
non-empty non-virtual proper base classes."

As far as I can see, both behaviours are permitted by the C++ standard.


I'm guessing that GCC's interpretation was the intended one?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20161007/cd044ca8/attachment.html>


More information about the cxx-abi-dev mailing list