summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/init/value3.C
blob: 487baabeceb68af3f3eb91c37f6e54fb58b1b041 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Testcase for value-initialization in new-expressions.
// { dg-do run }

#include <stdlib.h>
#include <string.h>

// Make sure that we return memory that isn't already set to 0.
void *operator new(size_t s)
{
  void *p = malloc (s);
  memset (p, 42, s);
  return p;
}

struct A { A() {} ~A() {} };
struct B { A a; int i; };

int main()
{
  B *p = new B();
  if (p->i != 0)
    abort();

  p = new B[2]();
  if (p[0].i != 0 || p[1].i != 0)
    abort();

  B(*p2)[2] = new B[2][2]();
  if (p2[0][0].i != 0 || p2[0][1].i != 0)
    abort();
}