Daily bump.
[gcc.git] / gcc / testsuite / g++.dg / cpp0x / zero-init1.C
blobd4b75c5fd9185b2537ea916abccf32bbc1155d79
1 // PR c++/117256
2 // { dg-do run { target c++11 } }
3 // { dg-options "-O0" }
5 void *operator new (decltype (sizeof 0), void *p) noexcept { return p; }
7 struct A { char c; int i; };
8 #if __cplusplus >= 201402L
9 struct B { A a; constexpr B (char x, int y) : a () { a.c = x; a.i = y; } };
10 #else
11 struct B { A a; B (char x, int y) : a () { a.c = x; a.i = y; } };
12 #endif
14 [[gnu::noipa]] void
15 foo ()
17   unsigned char buf[sizeof (B)];
18   A a1 = A ();
19   __builtin_memcpy (buf, &a1, sizeof (buf));
20   if (buf[1])
21     __builtin_abort ();
22   unsigned char m1 alignas (A) [sizeof (A)];
23   __builtin_memset (m1, -1, sizeof (m1));
24   A *a2 = new (m1) A ();
25   __builtin_memcpy (buf, a2, sizeof (*a2));
26   if (buf[1])
27     __builtin_abort ();
28   B b1 (42, -42);
29   __builtin_memcpy (buf, &b1, sizeof (b1));
30   if (buf[1])
31     __builtin_abort ();
32   unsigned char m2 alignas (B) [sizeof (B)];
33   B *b2 = new (m2) B (1, 2);
34   __builtin_memcpy (buf, b2, sizeof (*b2));
35   if (buf[1])
36     __builtin_abort ();
37 #if __cplusplus >= 201402L
38   constexpr B b3 (3, 4);
39   __builtin_memcpy (buf, &b3, sizeof (b3));
40   if (buf[1])
41     __builtin_abort ();
42 #endif
45 [[gnu::noipa]] void
46 bar (unsigned char *p)
48   (void) p;
51 [[gnu::noipa]] void
52 baz ()
54   unsigned char buf[256];
55   __builtin_memset (buf, -1, sizeof (buf));
56   bar (buf);
59 int
60 main ()
62   if (__builtin_offsetof (A, c) == 0
63       && __builtin_offsetof (A, i) != 1
64       && __builtin_offsetof (B, a) == 0
65       && sizeof (A) == sizeof (B))
66     {
67       baz ();
68       foo ();
69     }