2018-07-20 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / init / new16.C
blobc49f13f833f967ea0c3d59a72478d3ed616b3f86
1 // { dg-do run }
2 // { dg-options "-O2 -fstrict-aliasing" }
4 // Test that we don't let TBAA reorder an assignment across a
5 // placement new.
6 // See PR 29286.
8 typedef __SIZE_TYPE__ size_t;
10 inline void* operator new(size_t, void* __p) throw() { return __p; }
12 void __attribute__((noinline)) bar() {}
14 long __attribute__((noinline)) foo(double *p, int n)
16   long *f;
17   for (int i=0; i<n; ++i)
18   {
19     int *l = (int *)p;
20     *l = 0;
21     f = new (p) long;
22     *f = -1;
23   }
24   bar ();
25   return *f;
28 extern "C" void abort(void);
29 int main()
31   union {
32     int i;
33     long l;
34   } u;
35   if (foo((double *)&u, 1) != -1)
36     abort ();
37   return 0;