diff options
| author | Eric Fiselier <eric@efcs.ca> | 2016-11-23 01:18:56 +0000 |
|---|---|---|
| committer | Eric Fiselier <eric@efcs.ca> | 2016-11-23 01:18:56 +0000 |
| commit | 55b31b4e6934fb2e9dda6d7f0f2792b6c3420c05 (patch) | |
| tree | c5f77e59cac52f369638c0016587bf7b53a601c0 /libcxx/test/std/containers/sequences/deque | |
| parent | 80e66ac1d3cdb67a35ca0c57f8e4a00cacd0f019 (diff) | |
| download | bcm5719-llvm-55b31b4e6934fb2e9dda6d7f0f2792b6c3420c05.tar.gz bcm5719-llvm-55b31b4e6934fb2e9dda6d7f0f2792b6c3420c05.zip | |
[libcxx] Fix max_size() across all containers
Summary: The `max_size()` method of containers should respect both the allocator's reported `max_size` and the range of the `difference_type`. This patch makes all containers choose the smallest of those two values.
Reviewers: mclow.lists, EricWF
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D26885
llvm-svn: 287729
Diffstat (limited to 'libcxx/test/std/containers/sequences/deque')
| -rw-r--r-- | libcxx/test/std/containers/sequences/deque/deque.capacity/max_size.pass.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/libcxx/test/std/containers/sequences/deque/deque.capacity/max_size.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.capacity/max_size.pass.cpp new file mode 100644 index 00000000000..11ce9d2f689 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.capacity/max_size.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// size_type max_size() const; + +#include <cassert> +#include <deque> +#include <limits> +#include <type_traits> + +#include "test_allocator.h" +#include "test_macros.h" + +int main() { + { + typedef limited_allocator<int, 10> A; + typedef std::deque<int, A> C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator<int, (size_t)-1> A; + typedef std::deque<int, A> C; + const C::difference_type max_dist = + std::numeric_limits<C::difference_type>::max(); + C c; + assert(c.max_size() <= max_dist); + LIBCPP_ASSERT(c.max_size() == max_dist); + } + { + typedef std::deque<char> C; + const C::difference_type max_dist = + std::numeric_limits<C::difference_type>::max(); + C c; + assert(c.max_size() <= max_dist); + assert(c.max_size() <= alloc_max_size(c.get_allocator())); + } +} |

