This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bug gcc 2.95.


> I found the following behavior from gcc 2.95 on Solaris 2.7. When
> inheriting an empty base
> class with a static function, an extra word is added to the inherited
> class. In the example below I expect the object size of class B to to
> equal the size of class A (1 word). However, the compiler generates
> sizeof(B) = 8 and sizeof(A) = 4.

Tom,

Your observations are correct, but ... Where is the bug? Is any
program that ought to work not working because of that? Or is the
compiler accepting a program that should not be accepted?

The standard requires every object to have a different address. To
implement that requirement, the compiler adds a single byte member to
every empty class. In inheritance, this member also gets
inherited. This may sound strange, but should not cause any valid C++
program to break.

Of course, there is room for optimization, to reduce memory
consumption. With -fnew-abi, the compiler behaves as you expect. This
is, of course, binary-incompatible to what the compiler did for the
last few years.

Hope this helps,
Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]