Marshall Clow | 4951a48 | 2016-03-03 12:04:39 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Marshall Clow | d8b9e0b | 2016-03-14 02:51:50 +0000 | [diff] [blame] | 10 | // XFAIL: libcpp-no-exceptions |
Marshall Clow | 4951a48 | 2016-03-03 12:04:39 +0000 | [diff] [blame] | 11 | // <memory> |
| 12 | |
| 13 | // allocator: |
| 14 | // pointer allocate(size_type n, allocator<void>::const_pointer hint=0); |
| 15 | |
| 16 | #include <memory> |
| 17 | #include <cassert> |
| 18 | |
| 19 | template <typename T> |
| 20 | void test_max(size_t count) |
| 21 | { |
| 22 | std::allocator<T> a; |
Eric Fiselier | 4db388b | 2016-05-07 03:12:24 +0000 | [diff] [blame] | 23 | try { |
| 24 | a.allocate(count); |
| 25 | assert(false); |
| 26 | } catch (const std::exception &) { |
| 27 | } |
Marshall Clow | 4951a48 | 2016-03-03 12:04:39 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | int main() |
| 31 | { |
| 32 | { // Bug 26812 -- allocating too large |
| 33 | typedef double T; |
| 34 | std::allocator<T> a; |
| 35 | test_max<T> (a.max_size() + 1); // just barely too large |
| 36 | test_max<T> (a.max_size() * 2); // significantly too large |
| 37 | test_max<T> (((size_t) -1) / sizeof(T) + 1); // multiply will overflow |
| 38 | test_max<T> ((size_t) -1); // way too large |
| 39 | } |
| 40 | |
| 41 | { |
| 42 | typedef const double T; |
| 43 | std::allocator<T> a; |
| 44 | test_max<T> (a.max_size() + 1); // just barely too large |
| 45 | test_max<T> (a.max_size() * 2); // significantly too large |
| 46 | test_max<T> (((size_t) -1) / sizeof(T) + 1); // multiply will overflow |
| 47 | test_max<T> ((size_t) -1); // way too large |
| 48 | } |
| 49 | } |