From: Jonathan Wakely Date: Wed, 13 May 2015 12:21:45 +0000 (+0100) Subject: alloc_traits.h (_S_max_size): Implement LWG 2466. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=32e6a60e3a002b1f48592fd7d83956b98474cb2c;p=gcc.git alloc_traits.h (_S_max_size): Implement LWG 2466. * include/bits/alloc_traits.h (_S_max_size): Implement LWG 2466. * testsuite/20_util/allocator_traits/members/max_size.cc: Adjust. * testsuite/23_containers/forward_list/allocator/minimal.cc: Likewise. * testsuite/23_containers/map/allocator/minimal.cc: Likewise. * testsuite/23_containers/multimap/allocator/minimal.cc: Likewise. * testsuite/23_containers/multiset/allocator/minimal.cc: Likewise. * testsuite/23_containers/set/allocator/minimal.cc: Likewise. * testsuite/23_containers/unordered_map/allocator/minimal.cc: Likewise. * testsuite/23_containers/unordered_multimap/allocator/minimal.cc: Likewise. * testsuite/23_containers/unordered_multiset/allocator/minimal.cc: Likewise. * testsuite/23_containers/unordered_set/allocator/minimal.cc: Likewise. * testsuite/util/testsuite_allocator.h: Remove unused parameter. From-SVN: r223154 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index cd4395d798a..4b4ef39debf 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,23 @@ 2015-05-13 Jonathan Wakely + * include/bits/alloc_traits.h (_S_max_size): Implement LWG 2466. + * testsuite/20_util/allocator_traits/members/max_size.cc: Adjust. + * testsuite/23_containers/forward_list/allocator/minimal.cc: + Likewise. + * testsuite/23_containers/map/allocator/minimal.cc: Likewise. + * testsuite/23_containers/multimap/allocator/minimal.cc: Likewise. + * testsuite/23_containers/multiset/allocator/minimal.cc: Likewise. + * testsuite/23_containers/set/allocator/minimal.cc: Likewise. + * testsuite/23_containers/unordered_map/allocator/minimal.cc: + Likewise. + * testsuite/23_containers/unordered_multimap/allocator/minimal.cc: + Likewise. + * testsuite/23_containers/unordered_multiset/allocator/minimal.cc: + Likewise. + * testsuite/23_containers/unordered_set/allocator/minimal.cc: + Likewise. + * testsuite/util/testsuite_allocator.h: Remove unused parameter. + * acinclude.m4 (GLIBCXX_ENABLE_FILESYSTEM_TS): Re-enable on solaris. * configure: Regenerate. diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h index 12c6c12f187..e434261802f 100644 --- a/libstdc++-v3/include/bits/alloc_traits.h +++ b/libstdc++-v3/include/bits/alloc_traits.h @@ -315,7 +315,12 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_swap, typename = _Require<__not_<__has_max_size<_Alloc2>>>> static size_type _S_max_size(_Alloc2&, ...) - { return __gnu_cxx::__numeric_traits::__max; } + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2466. allocator_traits::max_size() default behavior is incorrect + return __gnu_cxx::__numeric_traits::__max + / sizeof(value_type); + } template struct __select_helper diff --git a/libstdc++-v3/testsuite/20_util/allocator_traits/members/max_size.cc b/libstdc++-v3/testsuite/20_util/allocator_traits/members/max_size.cc index 2678646f2fd..862ff4acc66 100644 --- a/libstdc++-v3/testsuite/20_util/allocator_traits/members/max_size.cc +++ b/libstdc++-v3/testsuite/20_util/allocator_traits/members/max_size.cc @@ -57,11 +57,22 @@ void test02() typedef std::allocator_traits> traits_type; traits_type::allocator_type a; auto size = std::numeric_limits::max(); - VERIFY( traits_type::max_size(a) == size ); + VERIFY( traits_type::max_size(a) == size / sizeof(X) ); +} + +void test03() +{ + bool test __attribute__((unused)) = true; + + typedef std::allocator_traits> traits_type; + traits_type::allocator_type a; + auto size = std::numeric_limits::max(); + VERIFY( traits_type::max_size(a) == size / sizeof(int) ); } int main() { test01(); test02(); + test03(); } diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/allocator/minimal.cc b/libstdc++-v3/testsuite/23_containers/forward_list/allocator/minimal.cc index 514489bbb1d..a6b3ce2c3e7 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/allocator/minimal.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/allocator/minimal.cc @@ -38,7 +38,7 @@ void test01() typedef std::forward_list test_type; test_type v(alloc_type{}); v.push_front(T()); - VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) ); + VERIFY( v.max_size() < traits_type::max_size(v.get_allocator()) ); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/map/allocator/minimal.cc b/libstdc++-v3/testsuite/23_containers/map/allocator/minimal.cc index bde62560ff1..3351f70ee02 100644 --- a/libstdc++-v3/testsuite/23_containers/map/allocator/minimal.cc +++ b/libstdc++-v3/testsuite/23_containers/map/allocator/minimal.cc @@ -42,7 +42,7 @@ void test01() typedef std::map test_type; test_type v(alloc_type{}); v = { test_type::value_type{} }; - VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) ); + VERIFY( v.max_size() < traits_type::max_size(v.get_allocator()) ); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/multimap/allocator/minimal.cc b/libstdc++-v3/testsuite/23_containers/multimap/allocator/minimal.cc index 433bcec2c81..1ac12133317 100644 --- a/libstdc++-v3/testsuite/23_containers/multimap/allocator/minimal.cc +++ b/libstdc++-v3/testsuite/23_containers/multimap/allocator/minimal.cc @@ -42,7 +42,7 @@ void test01() typedef std::multimap test_type; test_type v(alloc_type{}); v = { test_type::value_type{} }; - VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) ); + VERIFY( v.max_size() < traits_type::max_size(v.get_allocator()) ); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/multiset/allocator/minimal.cc b/libstdc++-v3/testsuite/23_containers/multiset/allocator/minimal.cc index 8d1b0ad91cc..b8ccb649897 100644 --- a/libstdc++-v3/testsuite/23_containers/multiset/allocator/minimal.cc +++ b/libstdc++-v3/testsuite/23_containers/multiset/allocator/minimal.cc @@ -40,7 +40,7 @@ void test01() typedef std::multiset test_type; test_type v(alloc_type{}); v = { test_type::value_type{} }; - VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) ); + VERIFY( v.max_size() < traits_type::max_size(v.get_allocator()) ); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/set/allocator/minimal.cc b/libstdc++-v3/testsuite/23_containers/set/allocator/minimal.cc index 369fc78585e..4364130699e 100644 --- a/libstdc++-v3/testsuite/23_containers/set/allocator/minimal.cc +++ b/libstdc++-v3/testsuite/23_containers/set/allocator/minimal.cc @@ -40,7 +40,7 @@ void test01() typedef std::set test_type; test_type v(alloc_type{}); v = { test_type::value_type{} }; - VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) ); + VERIFY( v.max_size() < traits_type::max_size(v.get_allocator()) ); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/allocator/minimal.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/allocator/minimal.cc index c267a3fd9ab..918cc8f132f 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_map/allocator/minimal.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/allocator/minimal.cc @@ -53,7 +53,7 @@ void test01() test_type v(alloc_type{}); v.emplace(std::piecewise_construct, std::make_tuple(T()), std::make_tuple(T())); - VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) ); + VERIFY( v.max_size() < traits_type::max_size(v.get_allocator()) ); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/allocator/minimal.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/allocator/minimal.cc index 3a66069cb8f..4e5bbc753d3 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multimap/allocator/minimal.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/allocator/minimal.cc @@ -54,7 +54,7 @@ void test01() test_type v(alloc_type{}); v.emplace(std::piecewise_construct, std::make_tuple(T()), std::make_tuple(T())); - VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) ); + VERIFY( v.max_size() < traits_type::max_size(v.get_allocator()) ); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/allocator/minimal.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/allocator/minimal.cc index 2820b92dbad..52641683529 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multiset/allocator/minimal.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/allocator/minimal.cc @@ -52,7 +52,7 @@ void test01() typedef std::unordered_multiset test_type; test_type v(alloc_type{}); v.insert(T()); - VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) ); + VERIFY( v.max_size() < traits_type::max_size(v.get_allocator()) ); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/allocator/minimal.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/allocator/minimal.cc index 8e950b5b338..666c3efb3ac 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/allocator/minimal.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/allocator/minimal.cc @@ -52,7 +52,7 @@ void test01() typedef std::unordered_set test_type; test_type v(alloc_type{}); v.insert(T()); - VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) ); + VERIFY( v.max_size() < traits_type::max_size(v.get_allocator()) ); } int main() diff --git a/libstdc++-v3/testsuite/util/testsuite_allocator.h b/libstdc++-v3/testsuite/util/testsuite_allocator.h index 642cef43d7d..090e5919fb9 100644 --- a/libstdc++-v3/testsuite/util/testsuite_allocator.h +++ b/libstdc++-v3/testsuite/util/testsuite_allocator.h @@ -491,7 +491,7 @@ namespace __gnu_test SimpleAllocator() noexcept { } template - SimpleAllocator(const SimpleAllocator& other) { } + SimpleAllocator(const SimpleAllocator&) { } Tp *allocate(std::size_t n) { return std::allocator().allocate(n); }