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]
Other format: [Raw text]

[Bug c++/13387] [3.3/3.4 regression] assignment to base class corrupts subclass


------- Additional Comments From Tasso dot Karkanis at rogers dot com  2003-12-12 13:59 -------
This is definitely a problem with alignment and packing.  I think it's related
to the implementation of the empty base class optimization.  I don't think it's
correct to pack members of a subclass into the padding at the end of a base class.

A base class could correctly use memcpy(this, other, sizeof(*this)) in its
assignment operator if it has all-POD members and no virtual functions.  This is
what the compiler-generated assignment operator effectively did.  Packing
members of a subclass into the padding could also cause unexpected behaviour in
this case.

To summarize, I think there are two related problems here:

1) the members of a subclass can get packed into the padding at the end of the
base class.

2) the compiler-generated assignment operator can overwrite members of a
subclass when they are packed into the padding of the base class.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13387


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