Fix PR C++/19351: integer overflow in operator new[]
[official-gcc.git] / gcc / testsuite / g++.dg / init / new38.C
blob1672f229d64b0e54ebda118cafd6bc78a2ab23c8
1 // { dg-do compile }
3 void
4 large_array_char(int n)
6   new char[n]
7     [1ULL << (sizeof(void *) * 4)]
8     [1ULL << (sizeof(void *) * 4)]; // { dg-error "size of array" }
11 template <typename T>
12 void
13 large_array_char_template(int n)
15   new char[n]
16     [1ULL << (sizeof(void *) * 4)]
17     [1ULL << (sizeof(void *) * 4)]; // { dg-error "size of array" }
21 template <typename T>
22 void
23 large_array_template1(int n)
25   new T[n] // { dg-error "size of array is too large" }
26     [(1ULL << (sizeof(void *) * 4)) / sizeof(T)]
27     [1ULL << (sizeof(void *) * 4)];
30 template <typename T>
31 void
32 large_array_template2(int n)
34   new T[n] // { dg-error "size of array is too large" }
35     [(1ULL << (sizeof(void *) * 4)) / sizeof(T)]
36     [1ULL << (sizeof(void *) * 4)];
39 template <typename T>
40 void
41 large_array_template3(int n)
43   new T[n] // { dg-error "size of array is too large" }
44     [(1ULL << (sizeof(void *) * 4)) / sizeof(T)]
45     [1ULL << (sizeof(void *) * 4)];
48 void
49 call_large_array_template(int n)
51   large_array_template1<char>(n);
52   large_array_template2<int>(n);
53   large_array_template3<double>(n);