commit 00f00caad92cbbc3d8893d5004df1ea2700d67af
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Sun May 10 19:50:14 2015 +0100
* 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.
@@ -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<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>
struct __select_helper
@@ -57,11 +57,22 @@ void test02()
typedef std::allocator_traits<unsized_allocator<X>> traits_type;
traits_type::allocator_type a;
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()
{
test01();
test02();
+ test03();
}
@@ -38,7 +38,7 @@ void test01()
typedef std::forward_list<T, alloc_type> 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()
@@ -42,7 +42,7 @@ void test01()
typedef std::map<T, U, Cmp, alloc_type> 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()
@@ -42,7 +42,7 @@ void test01()
typedef std::multimap<T, U, Cmp, alloc_type> 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()
@@ -40,7 +40,7 @@ void test01()
typedef std::multiset<T, Cmp, alloc_type> 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()
@@ -40,7 +40,7 @@ void test01()
typedef std::set<T, Cmp, alloc_type> 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()
@@ -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()
@@ -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()
@@ -52,7 +52,7 @@ void test01()
typedef std::unordered_multiset<T, hash, equal_to, alloc_type> 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()
@@ -52,7 +52,7 @@ void test01()
typedef std::unordered_set<T, hash, equal_to, alloc_type> 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()
@@ -491,7 +491,7 @@ namespace __gnu_test
SimpleAllocator() noexcept { }
template <class T>
- SimpleAllocator(const SimpleAllocator<T>& other) { }
+ SimpleAllocator(const SimpleAllocator<T>&) { }
Tp *allocate(std::size_t n)
{ return std::allocator<Tp>().allocate(n); }