| 1 |
// { dg-do compile } |
| 2 |
|
| 3 |
void |
| 4 |
nonconst(int n) |
| 5 |
{ |
| 6 |
new (long[n][n]); // { dg-error "variable length|array size|not a constant|runtime bound" } |
| 7 |
new long[n][n]; // { dg-error "variable length|array size|not a constant" } |
| 8 |
} |
| 9 |
|
| 10 |
template <typename T> |
| 11 |
void * |
| 12 |
callnew(int n) |
| 13 |
{ |
| 14 |
return new long[n][T::n]; |
| 15 |
} |
| 16 |
|
| 17 |
template <typename T> |
| 18 |
void * |
| 19 |
callnew_fail_1(int n) |
| 20 |
{ |
| 21 |
return new long[n][T::n]; // { dg-error "variable length|array size|usable in a constant" } |
| 22 |
} |
| 23 |
|
| 24 |
template <typename T> |
| 25 |
void * |
| 26 |
callnew_fail_2() |
| 27 |
{ |
| 28 |
return new long[T::n]; // { dg-error "size in array new" } |
| 29 |
} |
| 30 |
|
| 31 |
template <typename T> |
| 32 |
void * |
| 33 |
callnew_fail_3() |
| 34 |
{ |
| 35 |
return new T[2][T::n]; // { dg-error "could not convert|size of array has non-integral type|converted constant expression" } |
| 36 |
} |
| 37 |
|
| 38 |
struct T1 { |
| 39 |
static int n; |
| 40 |
}; |
| 41 |
|
| 42 |
struct T2 { |
| 43 |
static const double n = 2; // { dg-error "23:'constexpr' needed" "" { target c++11 } } |
| 44 |
// { dg-error "23:ISO C\\+\\+ forbids" "" { target c++98_only } .-1 } |
| 45 |
}; |
| 46 |
|
| 47 |
struct T3 { |
| 48 |
static const int n = 2; |
| 49 |
}; |
| 50 |
|
| 51 |
struct T4 { |
| 52 |
enum { n = 3 }; |
| 53 |
}; |
| 54 |
|
| 55 |
void |
| 56 |
test_callnew(int n) |
| 57 |
{ |
| 58 |
new long[0.2]; // { dg-error "integral or enumeration type" } |
| 59 |
callnew_fail_1<T1>(n); |
| 60 |
callnew_fail_2<T2>(); |
| 61 |
callnew_fail_3<T2>(); |
| 62 |
callnew<T3>(n); |
| 63 |
callnew<T4>(n); |
| 64 |
} |