This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/63157] may_alias doesn't work as expected in template nested types
- From: "haynberg at sig dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 04 Sep 2014 15:43:13 +0000
- Subject: [Bug c++/63157] may_alias doesn't work as expected in template nested types
- Auto-submitted: auto-generated
- References: <bug-63157-4 at http dot gcc dot gnu dot org/bugzilla/>
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