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/include/list | |
| 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/include/list')
| -rw-r--r-- | libcxx/include/list | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/libcxx/include/list b/libcxx/include/list index bebfff66cbf..98843d61f27 100644 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -571,6 +571,10 @@ protected: {return __size_alloc_.second();} _LIBCPP_INLINE_VISIBILITY + size_type __node_alloc_max_size() const _NOEXCEPT { + return __node_alloc_traits::max_size(__node_alloc()); + } + _LIBCPP_INLINE_VISIBILITY static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY @@ -904,7 +908,11 @@ public: bool empty() const _NOEXCEPT {return base::empty();} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT - {return numeric_limits<difference_type>::max();} + { + return std::min<size_type>( + base::__node_alloc_max_size(), + numeric_limits<difference_type >::max()); + } _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return base::begin();} |

