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 10struct B 11{ 12 B(); 13 int n; 14}; 15 16B::B() 17{ 18 n = 137; 19} 20 21 22struct D : public B 23{ 24 double x; 25}; 26 27 28D* 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 36int 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} 45