------- Comment #40 from matz at suse dot de 2006-01-23 11:21 ------- Mark, re your comment #38: (my comment #39 actually came before, but I forgot to press "Commit" :-/ ) the #pragma pack(1) does not influence DECL_PACKED. It is only set by attribute(packed). That's why the difference of behaviour between a struct under #pragma pack(1) vs. a struct with an attribute packed occurs.
I agree that it conceptually makes sense to implicitely have a zero-width bit-field never be DECL_PACKED (though this would deviate from pre-3.4). The ugly thing is, that current code in GCC seems to handle exactly this case differently. For instance in place_field(), we have this code: if (PCC_BITFIELD_TYPE_MATTERS && ! targetm.ms_bitfield_layout_p (rli->t) && TREE_CODE (field) == FIELD_DECL && type != error_mark_node && DECL_BIT_FIELD (field) && ! DECL_PACKED (field) && maximum_field_alignment == 0 && ! integer_zerop (DECL_SIZE (field)) .... the body contains a call to ADJUST_FIELD_ALIGN then. So if this is a zero-sized bitfield, then this ADJUST won't be done no matter what DECL_PACKED is, and it seems that this is wanted here (in difference to the other place in layout_decl, where zero-sized bitfield simply weren't handled). The comment above this code says that it's purpose is compatibility with PCC, so perhaps struct with zero-sized bitfields weren't handled at all by PCC, and this is a non-issue. I don't know. Otherwise it might be, that both places need to be handled the same way to not risk inconsistencies. It currently looks as if it also isn't handled consistently right now (another call to ADJUST_... misses to test DECL_PACKED at all for instance). Double-sigh. Anyway, I'll attach my current patch which implements the suggested behaviour, including zero-bitfield == !DECL_PACKED in layout_decl. And also a small testprogram showing information about different struct under different settings. It shows inconsistencies in 3.3, and with the patch 4.1 is more consistent (plus the case in wine, namely of using #pragma pack(1) still does the same as pre-3.4). -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22275