summaryrefslogtreecommitdiff
path: root/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp')
-rw-r--r--test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp b/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
new file mode 100644
index 000000000000..dc0bdd047c61
--- /dev/null
+++ b/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// XFAIL: libcpp-no-exceptions
+// <memory>
+
+// allocator:
+// pointer allocate(size_type n, allocator<void>::const_pointer hint=0);
+
+#include <memory>
+#include <cassert>
+
+template <typename T>
+void test_max(size_t count)
+{
+ std::allocator<T> a;
+ try {
+ a.allocate(count);
+ assert(false);
+ } catch (const std::exception &) {
+ }
+}
+
+int main()
+{
+ { // Bug 26812 -- allocating too large
+ typedef double T;
+ std::allocator<T> a;
+ test_max<T> (a.max_size() + 1); // just barely too large
+ test_max<T> (a.max_size() * 2); // significantly too large
+ test_max<T> (((size_t) -1) / sizeof(T) + 1); // multiply will overflow
+ test_max<T> ((size_t) -1); // way too large
+ }
+
+ {
+ typedef const double T;
+ std::allocator<T> a;
+ test_max<T> (a.max_size() + 1); // just barely too large
+ test_max<T> (a.max_size() * 2); // significantly too large
+ test_max<T> (((size_t) -1) / sizeof(T) + 1); // multiply will overflow
+ test_max<T> ((size_t) -1); // way too large
+ }
+}