[Bug c++/11376] [3.3/3.4 regression] mozilla-1.4 miscompiled
giovannibajo at libero dot it
gcc-bugzilla@gcc.gnu.org
Mon Jul 7 15:46:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11376
giovannibajo at libero dot it changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mmitchel at gcc dot gnu dot
| |org, nathan at gcc dot gnu
| |dot org
------- Additional Comments From giovannibajo at libero dot it 2003-07-07 15:46 -------
I believe the code is not legal. In main(), getter_addRefs calls
nsGetterAddRefs<mc0> constructor, which calls nsComPtr<mc0>::StartAssignment.
This function calls begin_assignment which casts &mRawPtr (whose type is
nsiSupports**) to void** through reinterpret_cast. Then, this void** is casted
to mc0** through reinterpret_cast. Now, mc0 is derived from nsiSupports. In
short, this looks like:
struct A {};
struct B : A {};
A* a;
void** pv = reinterpret_cast<void**>(&a);
B** pb = reinterpret_cast<B**>(pv);
*pb = new B;
assert (typeid(*a) == typeid(B));
I believe this violates ISO C++ aliasing rules, but I don't have a standard
handy to double-check now.
Kevin, can you please confirm that my snippet follows the code correctly?
Nathan, do you think the code is legal?
More information about the Gcc-bugs
mailing list