1 // Testcase for overflow handling in operator new[].
2 // Optimization of unnecessary overflow checks.
3 // In C++11 we throw bad_array_new_length instead.
4 // { dg-options -std=c++03 }
6 // { dg-xfail-run-if "AIX operator new" { powerpc-ibm-aix* } }
12 static size_t magic_allocation_size
13 = 1 + (size_t (1) << (sizeof (size_t) * 8 - 1));
15 struct exc : std::bad_alloc {
18 static size_t expected_size;
22 void *operator new[] (size_t sz)
24 if (sz != expected_size)
34 void *operator new[] (size_t sz)
36 if (sz != size_t (-1))
49 operator new (size_t sz) _GLIBCXX_THROW (std::bad_alloc)
51 if (sz != expected_size)
59 if (sizeof (pod_with_new) == 1)
60 expected_size = magic_allocation_size;
65 new pod_with_new[magic_allocation_size];
70 if (sizeof (with_new) == 1)
71 expected_size = magic_allocation_size;
76 new with_new[magic_allocation_size];
81 expected_size = magic_allocation_size;
83 new char[magic_allocation_size];
91 new pod_with_new[magic_allocation_size][2];
97 new with_new[magic_allocation_size][2];
103 new char[magic_allocation_size][2];
109 new non_pod[magic_allocation_size];