https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63157
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to haynberg from comment #2) > I recently read your old PR about placement new - > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=29286. > > Is using placement new also a means to prevent strict-aliasing optimizations > here? I don’t think so. Since the following also aborts. No, placement new constructs a new object so the contents you read below are undefined. > $ cat t.cpp > #include <memory> > #include <stdlib.h> > > struct msg { > long seq_no; > }; > > void check(char *p) > { > short *a = new (p) short; > *a = 5; > > msg *b = new (p) msg; > b->seq_no = 6; > > a = new (p) short; > if (*a == 5) > abort(); > } > > int main() > { > msg m[1]; > check((char*) m); > } > $ g++ -O3 -fno-strict-aliasing t.cpp && a.out > $ g++ -O3 t.cpp && a.out > Aborted