Commit 32e6a60e by Jonathan Wakely Committed by Jonathan Wakely

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
parent 0501dbd9
2015-05-13 Jonathan Wakely <jwakely@redhat.com> 2015-05-13 Jonathan Wakely <jwakely@redhat.com>
* 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. * acinclude.m4 (GLIBCXX_ENABLE_FILESYSTEM_TS): Re-enable on solaris.
* configure: Regenerate. * configure: Regenerate.
......
...@@ -315,7 +315,12 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_swap, ...@@ -315,7 +315,12 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_swap,
typename = _Require<__not_<__has_max_size<_Alloc2>>>> typename = _Require<__not_<__has_max_size<_Alloc2>>>>
static size_type static size_type
_S_max_size(_Alloc2&, ...) _S_max_size(_Alloc2&, ...)
{ return __gnu_cxx::__numeric_traits<size_type>::__max; } {
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2466. allocator_traits::max_size() default behavior is incorrect
return __gnu_cxx::__numeric_traits<size_type>::__max
/ sizeof(value_type);
}
template<typename _Alloc2> template<typename _Alloc2>
struct __select_helper struct __select_helper
......
...@@ -57,11 +57,22 @@ void test02() ...@@ -57,11 +57,22 @@ void test02()
typedef std::allocator_traits<unsized_allocator<X>> traits_type; typedef std::allocator_traits<unsized_allocator<X>> traits_type;
traits_type::allocator_type a; traits_type::allocator_type a;
auto size = std::numeric_limits<traits_type::size_type>::max(); auto size = std::numeric_limits<traits_type::size_type>::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<unsized_allocator<int>> traits_type;
traits_type::allocator_type a;
auto size = std::numeric_limits<traits_type::size_type>::max();
VERIFY( traits_type::max_size(a) == size / sizeof(int) );
} }
int main() int main()
{ {
test01(); test01();
test02(); test02();
test03();
} }
...@@ -38,7 +38,7 @@ void test01() ...@@ -38,7 +38,7 @@ void test01()
typedef std::forward_list<T, alloc_type> test_type; typedef std::forward_list<T, alloc_type> test_type;
test_type v(alloc_type{}); test_type v(alloc_type{});
v.push_front(T()); 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() int main()
......
...@@ -42,7 +42,7 @@ void test01() ...@@ -42,7 +42,7 @@ void test01()
typedef std::map<T, U, Cmp, alloc_type> test_type; typedef std::map<T, U, Cmp, alloc_type> test_type;
test_type v(alloc_type{}); test_type v(alloc_type{});
v = { test_type::value_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() int main()
......
...@@ -42,7 +42,7 @@ void test01() ...@@ -42,7 +42,7 @@ void test01()
typedef std::multimap<T, U, Cmp, alloc_type> test_type; typedef std::multimap<T, U, Cmp, alloc_type> test_type;
test_type v(alloc_type{}); test_type v(alloc_type{});
v = { test_type::value_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() int main()
......
...@@ -40,7 +40,7 @@ void test01() ...@@ -40,7 +40,7 @@ void test01()
typedef std::multiset<T, Cmp, alloc_type> test_type; typedef std::multiset<T, Cmp, alloc_type> test_type;
test_type v(alloc_type{}); test_type v(alloc_type{});
v = { test_type::value_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() int main()
......
...@@ -40,7 +40,7 @@ void test01() ...@@ -40,7 +40,7 @@ void test01()
typedef std::set<T, Cmp, alloc_type> test_type; typedef std::set<T, Cmp, alloc_type> test_type;
test_type v(alloc_type{}); test_type v(alloc_type{});
v = { test_type::value_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() int main()
......
...@@ -53,7 +53,7 @@ void test01() ...@@ -53,7 +53,7 @@ void test01()
test_type v(alloc_type{}); test_type v(alloc_type{});
v.emplace(std::piecewise_construct, v.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T())); 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() int main()
......
...@@ -54,7 +54,7 @@ void test01() ...@@ -54,7 +54,7 @@ void test01()
test_type v(alloc_type{}); test_type v(alloc_type{});
v.emplace(std::piecewise_construct, v.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T())); 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() int main()
......
...@@ -52,7 +52,7 @@ void test01() ...@@ -52,7 +52,7 @@ void test01()
typedef std::unordered_multiset<T, hash, equal_to, alloc_type> test_type; typedef std::unordered_multiset<T, hash, equal_to, alloc_type> test_type;
test_type v(alloc_type{}); test_type v(alloc_type{});
v.insert(T()); 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() int main()
......
...@@ -52,7 +52,7 @@ void test01() ...@@ -52,7 +52,7 @@ void test01()
typedef std::unordered_set<T, hash, equal_to, alloc_type> test_type; typedef std::unordered_set<T, hash, equal_to, alloc_type> test_type;
test_type v(alloc_type{}); test_type v(alloc_type{});
v.insert(T()); 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() int main()
......
...@@ -491,7 +491,7 @@ namespace __gnu_test ...@@ -491,7 +491,7 @@ namespace __gnu_test
SimpleAllocator() noexcept { } SimpleAllocator() noexcept { }
template <class T> template <class T>
SimpleAllocator(const SimpleAllocator<T>& other) { } SimpleAllocator(const SimpleAllocator<T>&) { }
Tp *allocate(std::size_t n) Tp *allocate(std::size_t n)
{ return std::allocator<Tp>().allocate(n); } { return std::allocator<Tp>().allocate(n); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment