]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / utilities / memory / default.allocator / allocator.members / allocate.size.pass.cpp
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
10 // UNSUPPORTED: libcpp-no-exceptions
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 #include "test_macros.h"
20
21 template <typename T>
22 void test_max(size_t count)
23 {
24     std::allocator<T> a;
25     try {
26         a.allocate(count);
27         assert(false);
28     } catch (const std::exception &) {
29     }
30 }
31
32 template <typename T>
33 void test()
34 {
35     // Bug 26812 -- allocating too large
36     std::allocator<T> a;
37     test_max<T> (a.max_size() + 1);                // just barely too large
38     test_max<T> (a.max_size() * 2);                // significantly too large
39     test_max<T> (((size_t) -1) / sizeof(T) + 1);   // multiply will overflow
40     test_max<T> ((size_t) -1);                     // way too large
41 }
42
43 int main()
44 {
45     test<double>();
46     LIBCPP_ONLY(test<const double>());
47 }