OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [expr/] [anew4.C] - Blame information for rev 801

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 693 jeremybenn
// { 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 
5
 
6
#include 
7
#include 
8
#include 
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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.