re PR libstdc++/56267 (unordered containers require Assignable hash function)
authorJonathan Wakely <jwakely.gcc@gmail.com>
Mon, 11 Feb 2013 00:19:29 +0000 (00:19 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 11 Feb 2013 00:19:29 +0000 (00:19 +0000)
PR libstdc++/56267
* include/bits/hashtable.h (__cache_default): Check if hash function
is copy assignable.
* testsuite/23_containers/unordered_set/56267.cc: New.
* testsuite/23_containers/unordered_set/instantiation_neg.cc: Adjust
dg-error line number.
* testsuite/23_containers/unordered_set/
not_default_constructible_hash_neg.cc: Likewise.

From-SVN: r195936

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/hashtable.h
libstdc++-v3/testsuite/23_containers/unordered_set/56267.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/unordered_set/instantiation_neg.cc
libstdc++-v3/testsuite/23_containers/unordered_set/not_default_constructible_hash_neg.cc

index 775ad99e2136ed51b77c27be6e75386d7642efd0..522c8851a00b260191297cb459a80f5e579740fc 100644 (file)
@@ -1,5 +1,14 @@
 2013-02-10  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
+       PR libstdc++/56267
+       * include/bits/hashtable.h (__cache_default): Check if hash function
+       is copy assignable.
+       * testsuite/23_containers/unordered_set/56267.cc: New.
+       * testsuite/23_containers/unordered_set/instantiation_neg.cc: Adjust
+       dg-error line number.
+       * testsuite/23_containers/unordered_set/
+       not_default_constructible_hash_neg.cc: Likewise.
+
        PR libstdc++/56278
        * include/bits/hashtable_policy.h (_Hash_code_base): Make default
        constructor public.
index 6515b71eef9f397a48735b7578b0d19c794bbecb..b82cda3fa21100d92480f066de635e9be9e8cb08 100644 (file)
@@ -43,8 +43,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       =  __not_<__and_<// Do not cache for fast hasher.
                       __is_fast_hash<_Hash>,
                       // Mandatory to make local_iterator default
-                      // constructible.
+                      // constructible and assignable.
                       is_default_constructible<_Hash>,
+                      is_copy_assignable<_Hash>,
                       // Mandatory to have erase not throwing.
                       __detail::__is_noexcept_hash<_Tp, _Hash>>>;
 
@@ -269,6 +270,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                    "Cache the hash code or make functors involved in hash code"
                    " and bucket index computation default constructible");
 
+      // When hash codes are not cached local iterator inherits from
+      // __hash_code_base above to compute node bucket index so it has to be
+      // assignable.
+      static_assert(__if_hash_not_cached<
+                     is_copy_assignable<__hash_code_base>>::value,
+                   "Cache the hash code or make functors involved in hash code"
+                   " and bucket index computation copy assignable");
+
     public:
       template<typename _Keya, typename _Valuea, typename _Alloca,
               typename _ExtractKeya, typename _Equala,
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/56267.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/56267.cc
new file mode 100644 (file)
index 0000000..0e9c71a
--- /dev/null
@@ -0,0 +1,35 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// Copyright (C) 2013 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// libstdc++/56267
+
+#include <unordered_set>
+
+struct hash : std::hash<int>
+{
+  hash& operator=(const hash&) = delete;
+};
+
+int main()
+{
+  std::unordered_set<int, hash> s{ 0, 1, 2 };
+  auto i = s.begin(0);
+  i = i;
+}
index 827691f2ce042704d35c8c211a254dcafbeaeddb..6712d626231e9664d011b04886708fa51ed1d55a 100644 (file)
@@ -19,7 +19,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-error "with noexcept" "" { target *-*-* } 251 }
+// { dg-error "with noexcept" "" { target *-*-* } 252 }
 
 #include <unordered_set>
 
index bd62a0808c70dee11c2c02ac5c7b24e39ffd0f22..53a25bc65b8961dabc224a076aaf84a80d4e55ef 100644 (file)
@@ -19,7 +19,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-error "default constructible" "" { target *-*-* } 267 }
+// { dg-error "default constructible" "" { target *-*-* } 268 }
 
 #include <unordered_set>