aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.8/gcc/testsuite/g++.dg/init/new37.C
blob: 82ca18b7aeba21b2d601dca32801f695cc1f8048 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// { dg-do compile }

void
nonconst(int n)
{
  new (long[n][n]); // { dg-error "variable length|array size|not a constant" }
  new long[n][n]; // { dg-error "variable length|array size|not a constant" }
}

template <typename T>
void *
callnew(int n)
{
  return new long[n][T::n];
}

template <typename T>
void *
callnew_fail_1(int n)
{
  return new long[n][T::n]; // { dg-error "variable length|array size|usable in a constant" }
}

template <typename T>
void *
callnew_fail_2()
{
  return new long[T::n]; // { dg-error "size in array new" }
}

template <typename T>
void *
callnew_fail_3()
{
  return new T[2][T::n]; // { dg-error "size of array has non-integral type" }
}

struct T1 {
  static int n;
};

struct T2 {
  static const double n = 2; // { dg-error "non-integral type" }
};

struct T3 {
  static const int n = 2;
};

struct T4 {
  enum { n = 3 };
};

void
test_callnew(int n)
{
  new long[0.2]; // { dg-error "integral or enumeration type" }
  callnew_fail_1<T1>(n);
  callnew_fail_2<T2>();
  callnew_fail_3<T2>();
  callnew<T3>(n);
  callnew<T4>(n);
}