This is the mail archive of the gcc@gcc.gnu.org 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]

Re: using offsetof with g++


On Nov 6, 2003, at 10:09 AM, Doug Evans wrote:

version = 3.3.2, i386-linux

cp/typeck.c has this:

/* Complain about other invalid uses of offsetof, even though they will
give the right answer. Note that we complain whether or not they
actually used the offsetof macro, since there's no way to know at this
point. So we just give a warning, instead of a pedwarn. */
if (null_object_p && CLASSTYPE_NON_POD_P (object_type))
{
warning ("invalid access to non-static data member `%D' of NULL object",
member);
warning ("(perhaps the `offsetof' macro was used incorrectly)");
}


No doubt there's a language citation for why this exists,
but I wonder if you guys would be amenable to adding an option
to turn this check off.

It's there: -Wno-invalid-offsetof


--Matt

P.S. Oh, and the language citation in question is from clause 18.1p5 of the
C++ Standard: "The macro offsetof accepts a restricted set of type arguments
in this International Standard. type shall be a POD structure or a POD
union."


The word "shall" in this clause means that our compiler is required to issue
a diagnostic for invalid uses. If we fail to issue a diagnostic, then the compiler
does not conform to the standard. Test suites should, and do, check this.



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