This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: option to silence warnings about offsetof and non-PODs
- From: Matt Austern <austern at apple dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 15 May 2003 13:58:56 -0700
- Subject: PATCH: option to silence warnings about offsetof and non-PODs
Some internal users at Apple have complained about the warning message
for applying offsetof to non-PODs. I've seen similar complaints from
people outside Apple.
The warning message is of course correct, and one could even argue that
it should be a hard error. Applying offsetof to a non-POD is
undefined. However, there are also a lot of cases where "POD" is too
strict a concept, where the offset of a data member is well defined and
the restriction is purely artificial. (I've raised this issue with the
C++ standards committee, and there's general agreement that "POD" was
chosen mostly for simplicity rather than because it's essential to the
notion of offsets.) Applying offsetof to simple non-POD types, such as
a simple struct with a constructor, is common. Users who are aware
that they're writing nonportable code, and who have deliberately chosen
to ignore the warning about it, should be able to do so.
This patch provides a switch, -W(no-)invalid-offsetof, to control the
warning. The warning is on by default. The only way to turn it off is
to use this switch explicitly; it is not controlled by -fpermissive or
by any other switch.
Documentation, test cases, and changelog entries included.
Bootstrapped and tested on i686-linux.
OK to commit to mainline?
--Matt
Attachment:
offsetpatch-fsf.txt
Description: Text document