| 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 |
int* allocate(int n) |
| 14 |
{ |
| 15 |
void *p; |
| 16 |
p = malloc(n * sizeof (int)); |
| 17 |
memset (p, 0xff, n * sizeof(int)); |
| 18 |
return new (p) int[n](); |
| 19 |
} |
| 20 |
|
| 21 |
int main() |
| 22 |
{ |
| 23 |
const int n = 17; |
| 24 |
int* p = allocate(n); |
| 25 |
for (int i = 0; i < n; ++i) |
| 26 |
if (p[i] != 0) |
| 27 |
abort (); |
| 28 |
exit (0); |
| 29 |
} |