Debian Codegraph @

gcc/testsuite/g++.dg/expr/anew2.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } }
3
4 // PR 11228: array operator new, with zero-initialization and a variable sized array.
5 // Regression test for PR
6 // Author: Matt Austern <[email protected]>
7
8
9 #include <new>
10 #include <stdlib.h>
11 #include <string.h>
12
13 double* allocate(int n)
14 {
15 void *p;
16 p = malloc(n * sizeof (double));
17 memset (p, 0xff, n * sizeof(double));
18 return new (p) double[n]();
19 }
20
21 int main()
22 {
23 const int n = 17;
24 double* p = allocate(n);
25 for (int i = 0; i < n; ++i)
26 if (p[i] != 0.0)
27 abort ();
28 exit (0);
29 }