OSDN Git Service

2009-02-03 Andrew Pinski <andrew_pinski@playstation.sony.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / expr / anew4.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 B
11 {
12   B();
13   int n;
14 };
15
16 B::B()
17 {
18   n = 137;
19 }
20
21
22 struct D : public B
23 {
24   double x;
25 };
26
27
28 D* allocate(int n)
29 {
30   void *p;
31   p = malloc(n * sizeof (D));
32   memset (p, 0xff, n * sizeof(D));
33   return new (p) D[n]();
34 }
35
36 int main()
37 {
38   const int n = 17;
39   D* p = allocate(n);
40   for (int i = 0; i < n; ++i)
41     if (p[i].n != 137 || p[i].x != 0)
42       abort ();
43   exit (0);
44 }