C++ 3.4.5 packed reference warning

Nathan Sidwell nathan@codesourcery.com
Wed Dec 7 16:03:00 GMT 2005


Steven L. Zook wrote:
> When I compile this using gcc rev 3.4.5 (m68k-elf):
> 
> struct A { char            B;
>            unsigned char & C; } __attribute__((packed));
> unsigned char D;
> A E = { 'F', D };
> 
> I get:
> 
> testpp.cpp:2: warning: ignoring packed attribute on unpacked non-POD
> field `unsigned char&A::C'
> 
> 
> sizeof( E ) == 6 (B, a byte of pad since m68k uses 16 bit alignment, and
> C).
> 
> This construct compiled without warning under 3.3.3 and gave sizeof( E )
> == 5.
> 
> Is this behavior under 3.4.5 (both the warning and the ignoring of the
> packed attribute on the reference member) proper (justified, necessary,
> good)?

It is bad to pack non-pod structs, because of alignment assumptions of member 
functions thereof.  The checking code just checks the non-podness of the type, 
as non-pod is a well defined term.  This could be relaxed.  File a bug report if 
needed.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk



More information about the Gcc mailing list