1 // Testcase for overflow handling in operator new[].
2 // Optimization of unnecessary overflow checks.
9 static size_t magic_allocation_size
10 = 1 + (size_t (1) << (sizeof (size_t) * 8 - 1));
12 struct exc : std::bad_alloc {
15 static size_t expected_size;
19 void *operator new[] (size_t sz)
21 if (sz != expected_size)
31 void *operator new[] (size_t sz)
33 if (sz != size_t (-1))
46 operator new (size_t sz) _GLIBCXX_THROW (std::bad_alloc)
48 if (sz != expected_size)
56 if (sizeof (pod_with_new) == 1)
57 expected_size = magic_allocation_size;
62 new pod_with_new[magic_allocation_size];
67 if (sizeof (with_new) == 1)
68 expected_size = magic_allocation_size;
73 new with_new[magic_allocation_size];
78 expected_size = magic_allocation_size;
80 new char[magic_allocation_size];
88 new pod_with_new[magic_allocation_size][2];
94 new with_new[magic_allocation_size][2];
100 new char[magic_allocation_size][2];
106 new non_pod[magic_allocation_size];