This is the mail archive of the 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]

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?


Attachment: offsetpatch-fsf.txt
Description: Text document

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