Nathan Sidwell wrote: > Jan Beulich wrote: > >> >> Why? It's broken. You just cannot embed something that requires >> alignment into something that doesn't guarantee alignment, except that >> for built-in types, the compiler can synthesize the necessary splitting, >> but Foo's assignment operator, in your example, may be totally unaware >> that it might get called with an unaligned object. > > > People write such code and expect it to work.
The code in question is: struct Foo { void operator=(Foo const &);}; struct Baz __attribute__((packed)) { char c; Foo m; } void Bar (Baz *ptr) { ptr->m = something; } I'm not sure it can be made to work, without making the base class version of Foo::operator= expect unaligned input, which seems an unreasonable pessimization. I would expect this code to be invalid, and either issue a diagnostic, or at least be considered undefined behavior. (In my idea world, ptr->m has type "packed Foo" in this case, and it's not permissible to binding a "packed Foo" to a "Foo const&", so this would be invalid, but I could live with undefined.) -- Mark Mitchell CodeSourcery, LLC [EMAIL PROTECTED] (916) 791-8304