[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
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@287729 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/__tree b/include/__tree
index f3f68b5..4c94fe5 100644
--- a/include/__tree
+++ b/include/__tree
@@ -1106,7 +1106,9 @@
_LIBCPP_INLINE_VISIBILITY
size_type max_size() const _NOEXCEPT
- {return __node_traits::max_size(__node_alloc());}
+ {return std::min<size_type>(
+ __node_traits::max_size(__node_alloc()),
+ numeric_limits<difference_type >::max());}
void clear() _NOEXCEPT;