invalid offsetof from non-POD type

Zack Weinberg zack@codesourcery.com
Tue Apr 22 17:19:00 GMT 2003


Gabriel Dos Reis <gdr@integrable-solutions.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



More information about the Gcc-bugs mailing list