alloc_traits.h (_S_max_size): Implement LWG 2466.
authorJonathan Wakely <jwakely@redhat.com>
Wed, 13 May 2015 12:21:45 +0000 (13:21 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 13 May 2015 12:21:45 +0000 (13:21 +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.

From-SVN: r223154

13 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/alloc_traits.h
libstdc++-v3/testsuite/20_util/allocator_traits/members/max_size.cc
libstdc++-v3/testsuite/23_containers/forward_list/allocator/minimal.cc
libstdc++-v3/testsuite/23_containers/map/allocator/minimal.cc
libstdc++-v3/testsuite/23_containers/multimap/allocator/minimal.cc
libstdc++-v3/testsuite/23_containers/multiset/allocator/minimal.cc
libstdc++-v3/testsuite/23_containers/set/allocator/minimal.cc
libstdc++-v3/testsuite/23_containers/unordered_map/allocator/minimal.cc
libstdc++-v3/testsuite/23_containers/unordered_multimap/allocator/minimal.cc
libstdc++-v3/testsuite/23_containers/unordered_multiset/allocator/minimal.cc
libstdc++-v3/testsuite/23_containers/unordered_set/allocator/minimal.cc
libstdc++-v3/testsuite/util/testsuite_allocator.h

index cd4395d798a9e171874b8700914ef606df5896e6..4b4ef39debf739beef3cc898c3ceb6aef41e69ca 100644 (file)
@@ -1,5 +1,23 @@
 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.
        * configure: Regenerate.
 
index 12c6c12f187b6f45bbb9ea705d550d9edbe753f4..e434261802fcf1b5f5e95616650da1b7a155f69d 100644 (file)
@@ -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
index 2678646f2fd42fdb9a4d79de715fbca75abe4866..862ff4acc668acf5f827e0f193deeac5ebb84968 100644 (file)
@@ -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();
 }
index 514489bbb1dc9400da37717fae090cc65fe3b5c4..a6b3ce2c3e7226b74aab7a564b4ac74587ee8372 100644 (file)
@@ -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()
index bde62560ff145cf08a166bd34693d4bf7bb725f4..3351f70ee0232c60781aa3923c0ea06a1e364403 100644 (file)
@@ -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()
index 433bcec2c818846db0ad37eedefebf7b70d64d45..1ac12133317370c551e9fad451a374d116010489 100644 (file)
@@ -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()
index 8d1b0ad91cc75910fb6e99ead4376b669fbec5ff..b8ccb649897781faaa56dfa96d99a4ad10a2da92 100644 (file)
@@ -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()
index 369fc78585e23538643161cd66f66447484cf384..4364130699e131fd1521178530f1c81fd3dbbde0 100644 (file)
@@ -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()
index c267a3fd9ab5502f4d3ef0c3bfba42e453539b72..918cc8f132f1c32d033fafe57fab27256b061915 100644 (file)
@@ -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()
index 3a66069cb8f29ffe079162ca2ec54efaac139ead..4e5bbc753d3e771b3151c9cd9d1d314e1b5bc559 100644 (file)
@@ -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()
index 2820b92dbad53ab74ab35faa3157269be6f45e25..5264168352908714a2e9a66e920866aae93e22ec 100644 (file)
@@ -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()
index 8e950b5b3388c366ff6c0405ce77f231fb85ecf2..666c3efb3accb47f8d2ba3a8079697a84b76dfa8 100644 (file)
@@ -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()
index 642cef43d7d1054f56b4e8bdba5a1565ba752812..090e5919fb988fac107f0cc0f7799604ff2c7800 100644 (file)
@@ -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); }