OSDN Git Service

PR c++/38648
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / expr / anew3.C
1 // { dg-do run }
2 // PR 11228: array operator new, with zero-initialization and a variable sized array.
3 // Regression test for PR 
4 // Author: Matt Austern <austern@apple.com>
5
6 #include <new>
7 #include <stdlib.h>
8 #include <string.h>
9
10 struct X
11 {
12   int a;
13   double b;
14 };
15
16 X* allocate(int n)
17 {
18   void *p;
19   p = malloc(n * sizeof (X));
20   memset (p, 0xff, n * sizeof(X));
21   return new (p) X[n]();
22 }
23
24 int main()
25 {
26   const int n = 17;
27   X* p = allocate(n);
28   for (int i = 0; i < n; ++i)
29     if (p[i].a != 0 || p[i].b != 0.0)
30       abort ();
31   exit (0);
32 }