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]

Re: PATCH: option to silence warnings about offsetof and non-PODs

On Friday, May 16, 2003, at 02:56 PM, Phil Edwards wrote:

On Thu, May 15, 2003 at 01:58:56PM -0700, Matt Austern wrote:
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.

Could perhaps some of this be included in the documentation paragraph?

What would you suggest? That paragraph is a mix of polemic, technical
information, and political information, some of which strikes me as
inappropriate for documentation. But how about something like this, as a
substitute for the documentation paragraph I proposed:

    @item -Wno-invalid-offsetof @r{(C++ only)}
    @opindex Wno-invalid-offsetof
    Suppress warnings from applying the @samp{offsetof} macro to a
    non-POD type.  According to the 1998 ISO C++ standard, applying
    @samp{offsetof} to a non-POD type is undefined.  In existing C++
    implementations,  however, @samp{offsetof} typically gives a
    meaningful results even when applied to certain kinds of non-POD
    types. (Such as a simple @samp{struct} that fails to be a POD type
    only because it has a constructor.)  This flag is for users who are
    aware that they are writing nonportable code and who have
    deliberately chosen to ignore the warning about it.

    The restrictions on @samp{offsetof} may be relaxed in a future
    version of the C++ standard.


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