[cxx-abi-dev] Question about tail padding

Jason Merrill jason at redhat.com
Fri Aug 16 00:25:56 UTC 2002


On Thu, 15 Aug 2002 17:39:12 +0100, Nathan Sidwell <nathan at codesourcery.com> wrote:

> mendell at ca.ibm.com wrote:
>> 
>> With allocation of derived classes in tail padding, what happens in the
>> following case
>> 
>>   struct S1 {
>>     virtual void f();
>>     int i;
>>     char c1;
>>   };                    // sizeof (S1) == 16 in 64 bit mode
>> 
>>   struct S2 : public S1 {
>>     char c2;            // allocated next to c1
>>   };                    // sizeof (S2) == 16 in 64 bit mode
>> 
>> S2 s2;
>> S1& rs1 = &s2;
>> S1 s1;
>> 
>> rs1 = s1;  // this will clobber the char member of s2.
>> 
>> Is this a reasonable interpretation?  Doesn't the assignment of S1s copy
>> the tail padding?

> No. You must arrange that S1::operator= does not copy tail padding.
> (S1 is non-pod, pods are different).

Actually, S1 is a POD.  Therefore, we don't allocate into its tail padding
for exactly this reason.

Jason



More information about the cxx-abi-dev mailing list