Index: .clang-format =================================================================== --- .clang-format +++ .clang-format @@ -1 +1,7 @@ BasedOnStyle: LLVM + +--- +Language: Cpp + +AlwaysBreakTemplateDeclarations: true +--- Index: include/__hash_table =================================================================== --- include/__hash_table +++ include/__hash_table @@ -1004,8 +1004,11 @@ _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT { - return allocator_traits<__pointer_allocator>::max_size( - __bucket_list_.get_deleter().__alloc()); + return std::min( + allocator_traits<__pointer_allocator>::max_size( + __bucket_list_.get_deleter().__alloc()), + numeric_limits::max() + ); } pair __node_insert_unique(__node_pointer __nd); @@ -1192,7 +1195,7 @@ _LIBCPP_INLINE_VISIBILITY size_type max_bucket_count() const _NOEXCEPT - {return __pointer_alloc_traits::max_size(__bucket_list_.get_deleter().__alloc());} + {return max_size(); } size_type bucket_size(size_type __n) const; _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT { Index: include/__tree =================================================================== --- include/__tree +++ 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( + __node_traits::max_size(__node_alloc()), + numeric_limits::max());} void clear() _NOEXCEPT; Index: include/deque =================================================================== --- include/deque +++ include/deque @@ -1310,7 +1310,9 @@ size_type size() const _NOEXCEPT {return __base::size();} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT - {return __alloc_traits::max_size(__base::__alloc());} + {return std::min( + __alloc_traits::max_size(__base::__alloc()), + numeric_limits::max());} void resize(size_type __n); void resize(size_type __n, const value_type& __v); void shrink_to_fit() _NOEXCEPT; Index: include/forward_list =================================================================== --- include/forward_list +++ include/forward_list @@ -734,8 +734,11 @@ bool empty() const _NOEXCEPT {return base::__before_begin()->__next_ == nullptr;} _LIBCPP_INLINE_VISIBILITY - size_type max_size() const _NOEXCEPT - {return numeric_limits::max();} + size_type max_size() const _NOEXCEPT { + return std::min( + __node_traits::max_size(base::__alloc()), + numeric_limits::max()); + } _LIBCPP_INLINE_VISIBILITY reference front() {return base::__before_begin()->__next_->__value_;} Index: include/list =================================================================== --- include/list +++ include/list @@ -571,6 +571,10 @@ {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 @@ bool empty() const _NOEXCEPT {return base::empty();} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT - {return numeric_limits::max();} + { + return std::min( + base::__node_alloc_max_size(), + numeric_limits::max()); + } _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return base::begin();} Index: include/vector =================================================================== --- include/vector +++ include/vector @@ -941,7 +941,8 @@ typename vector<_Tp, _Allocator>::size_type vector<_Tp, _Allocator>::max_size() const _NOEXCEPT { - return _VSTD::min(__alloc_traits::max_size(this->__alloc()), numeric_limits::max() / 2); // end() >= begin(), always + return _VSTD::min(__alloc_traits::max_size(this->__alloc()), + numeric_limits::max()); } // Precondition: __new_size > capacity() Index: test/std/containers/associative/map/map.access/max_size.pass.cpp =================================================================== --- test/std/containers/associative/map/map.access/max_size.pass.cpp +++ test/std/containers/associative/map/map.access/max_size.pass.cpp @@ -13,23 +13,39 @@ // size_type max_size() const; -#include #include +#include +#include +#include -#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" int main() { - { - typedef std::map M; - M m; - assert(m.max_size() != 0); + typedef std::pair KV; + { + typedef limited_allocator A; + typedef std::map, A> C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator A; + typedef std::map, A> C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + LIBCPP_ASSERT(c.max_size() == max_dist); } -#if TEST_STD_VER >= 11 { - typedef std::map, min_allocator>> M; - M m; - assert(m.max_size() != 0); + typedef std::map C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + assert(c.max_size() <= alloc_max_size(c.get_allocator())); } -#endif } Index: test/std/containers/associative/multimap/max_size.pass.cpp =================================================================== --- test/std/containers/associative/multimap/max_size.pass.cpp +++ test/std/containers/associative/multimap/max_size.pass.cpp @@ -13,23 +13,39 @@ // size_type max_size() const; -#include #include +#include +#include +#include -#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" int main() { - { - typedef std::multimap M; - M m; - assert(m.max_size() != 0); + typedef std::pair KV; + { + typedef limited_allocator A; + typedef std::multimap, A> C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator A; + typedef std::multimap, A> C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + LIBCPP_ASSERT(c.max_size() == max_dist); } -#if TEST_STD_VER >= 11 { - typedef std::multimap, min_allocator>> M; - M m; - assert(m.max_size() != 0); + typedef std::multimap C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + assert(c.max_size() <= alloc_max_size(c.get_allocator())); } -#endif } Index: test/std/containers/associative/multiset/max_size.pass.cpp =================================================================== --- test/std/containers/associative/multiset/max_size.pass.cpp +++ test/std/containers/associative/multiset/max_size.pass.cpp @@ -13,23 +13,38 @@ // size_type max_size() const; -#include #include +#include +#include +#include -#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" int main() { { - typedef std::multiset M; - M m; - assert(m.max_size() != 0); + typedef limited_allocator A; + typedef std::multiset, A> C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator A; + typedef std::multiset, A> C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + LIBCPP_ASSERT(c.max_size() == max_dist); } -#if TEST_STD_VER >= 11 { - typedef std::multiset, min_allocator> M; - M m; - assert(m.max_size() != 0); + typedef std::multiset C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + assert(c.max_size() <= alloc_max_size(c.get_allocator())); } -#endif } Index: test/std/containers/associative/set/max_size.pass.cpp =================================================================== --- test/std/containers/associative/set/max_size.pass.cpp +++ test/std/containers/associative/set/max_size.pass.cpp @@ -13,23 +13,38 @@ // size_type max_size() const; -#include #include +#include +#include +#include -#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" int main() { { - typedef std::set M; - M m; - assert(m.max_size() != 0); + typedef limited_allocator A; + typedef std::set, A> C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator A; + typedef std::set, A> C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + LIBCPP_ASSERT(c.max_size() == max_dist); } -#if TEST_STD_VER >= 11 { - typedef std::set, min_allocator> M; - M m; - assert(m.max_size() != 0); + typedef std::set C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + assert(c.max_size() <= alloc_max_size(c.get_allocator())); } -#endif } Index: test/std/containers/sequences/deque/deque.capacity/max_size.pass.cpp =================================================================== --- /dev/null +++ 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. +// +//===----------------------------------------------------------------------===// + +// + +// size_type max_size() const; + +#include +#include +#include +#include + +#include "test_allocator.h" +#include "test_macros.h" + +int main() { + { + typedef limited_allocator A; + typedef std::deque C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator A; + typedef std::deque C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + LIBCPP_ASSERT(c.max_size() == max_dist); + } + { + typedef std::deque C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + assert(c.max_size() <= alloc_max_size(c.get_allocator())); + } +} Index: test/std/containers/sequences/forwardlist/max_size.pass.cpp =================================================================== --- test/std/containers/sequences/forwardlist/max_size.pass.cpp +++ test/std/containers/sequences/forwardlist/max_size.pass.cpp @@ -11,25 +11,38 @@ // size_type max_size() const; -#include #include +#include +#include +#include -#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" int main() { { - typedef int T; - typedef std::forward_list C; - C c; - assert(c.max_size() > 0); + typedef limited_allocator A; + typedef std::forward_list C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator A; + typedef std::forward_list C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + LIBCPP_ASSERT(c.max_size() == max_dist); } -#if TEST_STD_VER >= 11 { - typedef int T; - typedef std::forward_list> C; - C c; - assert(c.max_size() > 0); + typedef std::forward_list C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + assert(c.max_size() <= alloc_max_size(c.get_allocator())); } -#endif } Index: test/std/containers/sequences/list/list.capacity/max_size.pass.cpp =================================================================== --- /dev/null +++ test/std/containers/sequences/list/list.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. +// +//===----------------------------------------------------------------------===// + +// + +// size_type max_size() const noexcept + +#include +#include +#include +#include + +#include "test_allocator.h" +#include "test_macros.h" + +int main() { + { + typedef limited_allocator A; + typedef std::list C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator A; + typedef std::list C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + LIBCPP_ASSERT(c.max_size() == max_dist); + } + { + typedef std::list C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + assert(c.max_size() <= alloc_max_size(c.get_allocator())); + } +} Index: test/std/containers/sequences/vector/vector.capacity/max_size.pass.cpp =================================================================== --- /dev/null +++ test/std/containers/sequences/vector/vector.capacity/max_size.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// size_type max_size() const; + +#include +#include +#include +#include + +#include "test_allocator.h" +#include "test_macros.h" + + +int main() { + { + typedef limited_allocator A; + typedef std::vector C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator A; + typedef std::vector C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + LIBCPP_ASSERT(c.max_size() == max_dist); + } + { + typedef std::vector C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + assert(c.max_size() <= alloc_max_size(c.get_allocator())); + } +} Index: test/std/containers/unord/unord.map/max_size.pass.cpp =================================================================== --- test/std/containers/unord/unord.map/max_size.pass.cpp +++ test/std/containers/unord/unord.map/max_size.pass.cpp @@ -9,28 +9,45 @@ // -// template , class Pred = equal_to, -// class Alloc = allocator>> // class unordered_map // size_type max_size() const; -#include #include +#include +#include +#include -#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" int main() { - { - std::unordered_map u; - assert(u.max_size() > 0); + typedef std::pair KV; + { + typedef limited_allocator A; + typedef std::unordered_map, std::equal_to, A> + C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator A; + typedef std::unordered_map, std::equal_to, A> + C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + LIBCPP_ASSERT(c.max_size() == max_dist); } -#if TEST_STD_VER >= 11 { - std::unordered_map, std::equal_to, - min_allocator>> u; - assert(u.max_size() > 0); + typedef std::unordered_map C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + assert(c.max_size() <= alloc_max_size(c.get_allocator())); } -#endif } Index: test/std/containers/unord/unord.multimap/max_size.pass.cpp =================================================================== --- test/std/containers/unord/unord.multimap/max_size.pass.cpp +++ test/std/containers/unord/unord.multimap/max_size.pass.cpp @@ -9,28 +9,47 @@ // -// template , class Pred = equal_to, -// class Alloc = allocator>> // class unordered_multimap // size_type max_size() const; -#include #include +#include +#include +#include -#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" int main() { - { - std::unordered_multimap u; - assert(u.max_size() > 0); + typedef std::pair KV; + { + typedef limited_allocator A; + typedef std::unordered_multimap, + std::equal_to, A> + C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator A; + typedef std::unordered_multimap, + std::equal_to, A> + C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + LIBCPP_ASSERT(c.max_size() == max_dist); } -#if TEST_STD_VER >= 11 { - std::unordered_multimap, std::equal_to, - min_allocator>> u; - assert(u.max_size() > 0); + typedef std::unordered_multimap C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + assert(c.max_size() <= alloc_max_size(c.get_allocator())); } -#endif } Index: test/std/containers/unord/unord.multiset/max_size.pass.cpp =================================================================== --- test/std/containers/unord/unord.multiset/max_size.pass.cpp +++ test/std/containers/unord/unord.multiset/max_size.pass.cpp @@ -9,28 +9,46 @@ // -// template , class Pred = equal_to, -// class Alloc = allocator> // class unordered_multiset // size_type max_size() const; -#include #include +#include +#include +#include -#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" int main() { { - std::unordered_multiset u; - assert(u.max_size() > 0); + typedef limited_allocator A; + typedef std::unordered_multiset, std::equal_to, + A> + C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator A; + typedef std::unordered_multiset, std::equal_to, + A> + C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + LIBCPP_ASSERT(c.max_size() == max_dist); } -#if TEST_STD_VER >= 11 { - std::unordered_multiset, - std::equal_to, min_allocator> u; - assert(u.max_size() > 0); + typedef std::unordered_multiset C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + assert(c.max_size() <= alloc_max_size(c.get_allocator())); } -#endif } Index: test/std/containers/unord/unord.set/max_size.pass.cpp =================================================================== --- test/std/containers/unord/unord.set/max_size.pass.cpp +++ test/std/containers/unord/unord.set/max_size.pass.cpp @@ -9,28 +9,42 @@ // -// template , class Pred = equal_to, -// class Alloc = allocator> // class unordered_set // size_type max_size() const; -#include #include +#include +#include +#include -#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" int main() { { - std::unordered_set u; - assert(u.max_size() > 0); + typedef limited_allocator A; + typedef std::unordered_set, std::equal_to, A> C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator A; + typedef std::unordered_set, std::equal_to, A> C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + LIBCPP_ASSERT(c.max_size() == max_dist); } -#if TEST_STD_VER >= 11 { - std::unordered_set, - std::equal_to, min_allocator> u; - assert(u.max_size() > 0); + typedef std::unordered_set C; + const C::difference_type max_dist = + std::numeric_limits::max(); + C c; + assert(c.max_size() <= max_dist); + assert(c.max_size() <= alloc_max_size(c.get_allocator())); } -#endif } Index: test/support/test_allocator.h =================================================================== --- test/support/test_allocator.h +++ test/support/test_allocator.h @@ -20,6 +20,12 @@ #include "test_macros.h" +template +inline size_t alloc_max_size(Alloc const &a) { + typedef std::allocator_traits AT; + return AT::max_size(a); +} + class test_alloc_base { protected: