------- Comment #10 from rguenth at gcc dot gnu dot org 2010-05-18 14:58 ------- (In reply to comment #9) > But the standard says in [basic.types] that "For any trivially copyable type > T, > if two pointers to T point to distinct T objects obj1 and obj2, where neither > obj1 nor obj2 is a base-class subobject, if the underlying bytes (1.7) making > up obj1 are copied into obj2,40 obj2 shall subsequently hold the same value as > obj1."
Yep. But an assignment is not a byte-copy and exactly the assignment is what invokes the undefined behavior (not the subsequent access). So, struct X { char data[ sizeof( float ) ]; }; int main() { X x1; new( &x1.data ) float( 3.14f ); X x2 = x1; GCC sees this as reading the float object you made live in x1.data via an lvalue of type X and thus decides that the float object is unused and removes it. -- rguenth at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rguenth at gcc dot gnu dot | |org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44164