https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63157

--- Comment #2 from haynberg at sig dot com ---
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.

$ 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

Reply via email to