This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13387] [3.3/3.4 regression] assignment to base class corrupts subclass
- From: "Tasso dot Karkanis at rogers dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 Dec 2003 14:00:01 -0000
- Subject: [Bug c++/13387] [3.3/3.4 regression] assignment to base class corrupts subclass
- References: <20031212022354.13387.Tasso.Karkanis@rogers.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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