C++ PATCH to offsetof handling

Jason Merrill jason@redhat.com
Fri Feb 1 11:29:00 GMT 2002


Red Hat Bugzilla bug 55063 complains that an offsetof-like construct that
worked in 2.95 no longer works in 3.0.  This happens because due to layout
changes, a single inheritance hierarchy may not always have bases at offset
0, so g++ thinks an adjustment might be necessary and gives up.

This is actually only a problem if the base conversion crosses a virtual
inheritance link (and thus relies on the contents of an object we don't
have), so I've tightened the error to only cover that case.  At the same
time, this code pattern is dubious at best due to the restriction on
offsetof to only work with POD types, so I've added a warning.  So we
complain about more cases, but not as vehemently for some.

Tested i686-pc-linux-gnu.  Test in g++.dg/abi/offsetof.C.
Regression from 2.95.  Applied to trunk.

2002-02-01  Jason Merrill  <jason@redhat.com>

	* typeck.c (build_component_ref): Always complain about offsetof
	constructs on non-PODs.  Only make it an error for members of
	virtual bases.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/x-patch
Size: 2815 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20020201/91290ff5/attachment.bin>


More information about the Gcc-patches mailing list