This is the mail archive of the gcc-bugs@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: invalid offsetof from non-POD type


Gabriel Dos Reis <gdr at integrable-solutions dot net> writes:

> | 2) multiple non-virtual inheritance is no more a problem than in other data
> | member access situations.
>
> Then, one neeeds to spell out the constraints: Is member access
> checked (presumably, yes since you proposed one takes standard
> wordings)?  What about multiple or ambiguous members? 

Suppose the following definition:

For any object X of type T with data member m of type t, 
offsetof(T, m) is defined to be a value of type ptrdiff_t which
satisfies the equation

    (t *)((char *)&X + offsetof(T, m)) == &X.m

If (for whatever reason) &X.m would be a constraint violation, or if
&X.m is legitimate but there isn't exactly one value which satisfies
the equation, then offsetof(T, m) is a constraint violation.

I do not claim to be a C++ expert.  Does that cover all the
circumstances you are worried about?  An intended property is that
under no circumstances does offsetof(T, m) induce undefined behavior;
it is either well-defined or a constraint violation (-> diagnostic,
translation unit rejected).

zw


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