When a packed non-POD struct is included in another packed struct, the outer struct layout changes depending on whether -Wpacked is used or not. It seems wrong that a warning option affects data layout and code generation.
The same behavior is observed with 4.4.2, 4.3.4, 4.2.1, 4.1.2. It could be related to bug 26670. % cat packed_nonpod.cpp extern "C" int printf (__const char *__restrict __format, ...); struct INNER { virtual int foo() const { return 1; } } __attribute__ ((packed)); struct OUTER { char c; INNER inner; } __attribute__ ((packed)); int main() { OUTER outer; printf("sizeof(outer) = %u\n", sizeof(outer)); printf("offset(inner) = %u\n", (char *)&outer.inner - (char *)&outer); return 0; } % g++ packed_nonpod.cpp % a.out sizeof(outer) = 5 offset(inner) = 1 % g++ packed_nonpod.cpp -Wpacked packed_nonpod.cpp:3: warning: packed attribute is unnecessary for 'INNER' packed_nonpod.cpp:9: warning: ignoring packed attribute because of unpacked non-POD field 'INNER OUTER::inner' % a.out sizeof(outer) = 8 offset(inner) = 4 -- Summary: -Wpacked option changes the layout of packed non-POD structs Product: gcc Version: 4.4.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: nenad at tensilica dot com GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41788