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/associative/map | |
| 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/associative/map')
| -rw-r--r-- | libcxx/test/std/containers/associative/map/map.access/max_size.pass.cpp | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/libcxx/test/std/containers/associative/map/map.access/max_size.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/max_size.pass.cpp index c67d8b1f674..82a817a1f4a 100644 --- a/libcxx/test/std/containers/associative/map/map.access/max_size.pass.cpp +++ b/libcxx/test/std/containers/associative/map/map.access/max_size.pass.cpp @@ -13,23 +13,39 @@ // size_type max_size() const; -#include <map> #include <cassert> +#include <limits> +#include <map> +#include <type_traits> -#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" int main() { - { - typedef std::map<int, double> M; - M m; - assert(m.max_size() != 0); + typedef std::pair<const int, int> KV; + { + typedef limited_allocator<KV, 10> A; + typedef std::map<int, int, std::less<int>, A> C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator<KV, (size_t)-1> A; + typedef std::map<int, int, std::less<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); } -#if TEST_STD_VER >= 11 { - typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; - M m; - assert(m.max_size() != 0); + typedef std::map<char, int> 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())); } -#endif } |

