This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/63157] may_alias doesn't work as expected in template nested types


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]