OSDN Git Service

2006-12-01 Ryan Mansfield <rmansfield@qnx.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / expr / anew4.C
1 // { dg-do run { xfail *-*-* } }
2 // XFAILed until PR2123 is fixed
3 // PR 11228: array operator new, with zero-initialization and a variable sized array.
4 // Regression test for PR 
5 // Author: Matt Austern <austern@apple.com>
6
7 #include <new>
8 #include <stdlib.h>
9 #include <string.h>
10
11 struct B
12 {
13   B();
14   int n;
15 };
16
17 B::B()
18 {
19   n = 137;
20 }
21
22
23 struct D : public B
24 {
25   double x;
26 };
27
28
29 D* allocate(int n)
30 {
31   void *p;
32   p = malloc(n * sizeof (D));
33   memset (p, 0xff, n * sizeof(D));
34   return new (p) D[n]();
35 }
36
37 int main()
38 {
39   const int n = 17;
40   D* p = allocate(n);
41   for (int i = 0; i < n; ++i)
42     if (p[i].n != 137 || p[i].x != 0)
43       abort ();
44   exit (0);
45 }