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: g++.dg/ext/packed3.C


>>> Nathan Sidwell <nathan@codesourcery.com> 07.12.05 16:58:11 >>>
>Jan Beulich wrote:
>> This test contains three invocations of Ref(), but only two of them
are
>> considered ill. What I'd like to get an explanation for is why the
third
>> (middle) instance is considered correct. After all, the u member of
>> Packed is packed, and hence all the members of Unpacked in that
context
>> are, too. Namely, even if the object referenced by p is properly
>> aligned, p.u isn't and hence p.u.i isn't either.
>> 
>> I'm asking this because for *-*-netware*, which uses packed
structures
>> by default, this test fails with an error message like the ones
expected
>> on the other two calls to Ref().
>
>Although Unpacked is a pod type, if it contained non-static member
functions, 
>those member functions would expect a this pointer that is correctly
aligned. 

And that is precisely the reason why I think binding a reference to the
whole object or any of its members, when the object itself is a member
of a packed object, is illegal, hence requiring a diagnostic (unless,
like for both other cases, the default is to pack structures).

>We have two options
>1) don't pack fields of structure type
>2) don't pack fields of non-pod or non-static member function
containing structs
>
>#2 means the alignment of your field can change, depending on whether
the 
>field's type contains a non-static member or not.  C++ has no term for
such a class.
>
>#1) breaks GNU C compatibility, I think.
>
>I'm not sure what the best answer is here.
>
>If your system packs structs by default, you should not be getting the
warning 
>on any of the uses.

But I do, and if I use a native Linux compiler with -fpack-struct, I
also get it (along with a second one on one of the two other
instances).

Jan


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