blob: dc0bdd047c61ae005ee6a61cbee703ba0ddb3ab7 [file] [log] [blame]
Marshall Clow4951a482016-03-03 12:04:39 +00001//===----------------------------------------------------------------------===//
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 Clowd8b9e0b2016-03-14 02:51:50 +000010// XFAIL: libcpp-no-exceptions
Marshall Clow4951a482016-03-03 12:04:39 +000011// <memory>
12
13// allocator:
14// pointer allocate(size_type n, allocator<void>::const_pointer hint=0);
15
16#include <memory>
17#include <cassert>
18
19template <typename T>
20void test_max(size_t count)
21{
22 std::allocator<T> a;
Eric Fiselier4db388b2016-05-07 03:12:24 +000023 try {
24 a.allocate(count);
25 assert(false);
26 } catch (const std::exception &) {
27 }
Marshall Clow4951a482016-03-03 12:04:39 +000028}
29
30int 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}