re PR libstdc++/51558 (Declaration of unspecialized std::hash<_Tp>::operator()(_Tp...
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 15 Dec 2011 22:15:21 +0000 (22:15 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 15 Dec 2011 22:15:21 +0000 (22:15 +0000)
2011-12-15  Paolo Carlini  <paolo.carlini@oracle.com>
    Jonathan Wakely  <jwakely.gcc@gmail.com>

PR libstdc++/51558
* include/bits/functional_hash.h (struct hash): Add static_assert.
* src/compatibility-c++0x.cc: Adjust compatibility definitions.
* testsuite/23_containers/unordered_map/erase/51142.cc: Adjust.
* testsuite/23_containers/unordered_set/erase/51142.cc: Likewise.
* testsuite/23_containers/unordered_multimap/erase/51142.cc: Likewise.
* testsuite/23_containers/unordered_multiset/erase/51142.cc: Likewise.

Co-Authored-By: Jonathan Wakely <jwakely.gcc@gmail.com>
From-SVN: r182392

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/functional_hash.h
libstdc++-v3/src/compatibility-c++0x.cc
libstdc++-v3/testsuite/23_containers/unordered_map/erase/51142.cc
libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/51142.cc
libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/51142.cc
libstdc++-v3/testsuite/23_containers/unordered_set/erase/51142.cc

index 38e0ff229cef5e24bcaef70549f0b5141c5b46c8..f050ad903c09214a96d65e5bf8cbf953d74a97c6 100644 (file)
@@ -1,3 +1,14 @@
+2011-12-15  Paolo Carlini  <paolo.carlini@oracle.com>
+           Jonathan Wakely  <jwakely.gcc@gmail.com>
+
+       PR libstdc++/51558
+       * include/bits/functional_hash.h (struct hash): Add static_assert.
+       * src/compatibility-c++0x.cc: Adjust compatibility definitions.
+       * testsuite/23_containers/unordered_map/erase/51142.cc: Adjust.
+       * testsuite/23_containers/unordered_set/erase/51142.cc: Likewise.
+       * testsuite/23_containers/unordered_multimap/erase/51142.cc: Likewise.
+       * testsuite/23_containers/unordered_multiset/erase/51142.cc: Likewise.
+
 2011-12-15  Benjamin Kosnik  <bkoz@redhat.com>
 
        * testsuite/22_locale/num_put/put/char/9780-2.cc: Add test for "C"
index 2b82b21f71603cac0056b610f7dffa5314150039..e892159d4499cfc3bdc0e1502b2d2ba374ca21e3 100644 (file)
@@ -57,8 +57,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Tp>
     struct hash : public __hash_base<size_t, _Tp>
     {
-      size_t
-      operator()(_Tp __val) const;
+      static_assert(sizeof(_Tp) < 0,
+                   "std::hash is not specialized for this type");
+      size_t operator()(const _Tp&) const noexcept;
     };
 
   /// Partial specializations for pointer types.
index c5e1db092a57858a54b68c06a7d1736532c1bd8e..03c58d244f2c560e0ab33b03f661bd2febf79662 100644 (file)
@@ -52,36 +52,60 @@ namespace std _GLIBCXX_VISIBILITY(default)
 
 #ifndef _GLIBCXX_LONG_DOUBLE_COMPAT_IMPL
   template<>
-    size_t
-    hash<string>::operator()(string __s) const
-    { return _Hash_impl::hash(__s.data(), __s.length()); }
+    struct hash<string>
+    {
+      size_t operator()(string) const;
+    };
+
+  size_t
+  hash<string>::operator()(string __s) const
+  { return _Hash_impl::hash(__s.data(), __s.length()); }
 
   template<>
-    size_t
-    hash<const string&>::operator()(const string& __s) const
-    { return _Hash_impl::hash(__s.data(), __s.length()); }
+    struct hash<const string&>
+    {
+      size_t operator()(const string&) const;
+    };
+
+  size_t
+  hash<const string&>::operator()(const string& __s) const
+  { return _Hash_impl::hash(__s.data(), __s.length()); }
 
 #ifdef _GLIBCXX_USE_WCHAR_T
   template<>
-    size_t
-    hash<wstring>::operator()(wstring __s) const
-    { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); }
+    struct hash<wstring>
+    { 
+      size_t operator()(wstring) const;
+    };
+
+  size_t
+  hash<wstring>::operator()(wstring __s) const
+  { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); }
 
   template<>
-    size_t
-    hash<const wstring&>::operator()(const wstring& __s) const
-    { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); }
+    struct hash<const wstring&>
+    {
+      size_t operator()(const wstring&) const;
+    };
+
+  size_t
+  hash<const wstring&>::operator()(const wstring& __s) const
+  { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); }
 #endif
 #endif
 
   template<>
-    size_t
-    hash<error_code>::operator()(error_code __e) const
+    struct hash<error_code>
     {
-      const size_t __tmp = std::_Hash_impl::hash(__e._M_value);
-      return std::_Hash_impl::__hash_combine(__e._M_cat, __tmp);
-    }
+      size_t operator()(error_code) const;
+    };
 
+  size_t
+  hash<error_code>::operator()(error_code __e) const
+  {
+    const size_t __tmp = std::_Hash_impl::hash(__e._M_value);
+    return std::_Hash_impl::__hash_combine(__e._M_cat, __tmp);
+  }
 
   // gcc-4.7.0
   // <chrono> changes is_monotonic to is_steady.
index eab637df2352f82d556cf285ec072783a5294bde..7986fb23a369c579efb894389ba2126ea60d3286 100644 (file)
@@ -27,12 +27,15 @@ struct X
   X(T&) {}
 };
 
+struct X_hash
+{ std::size_t operator()(const X&) const { return 0; } };
+
 bool operator==(const X&, const X&) { return false; }
 
 // LWG 2059.
-void erasor(std::unordered_map<X, int>& s, X x)
+void erasor(std::unordered_map<X, int, X_hash>& s, X x)
 {
-  std::unordered_map<X, int>::iterator it = s.find(x);
+  std::unordered_map<X, int, X_hash>::iterator it = s.find(x);
   if (it != s.end())
     s.erase(it);
 }
index 678aa5dd9897a9ce8a3fd76fdf2eeeb600116886..0d434ac8a683b0e668f07c93e08d5525f42fbb60 100644 (file)
@@ -27,12 +27,15 @@ struct X
   X(T&) {}
 };
 
+struct X_hash
+{ std::size_t operator()(const X&) const { return 0; } };
+
 bool operator==(const X&, const X&) { return false; }
 
 // LWG 2059.
-void erasor(std::unordered_multimap<X, int>& s, X x)
+void erasor(std::unordered_multimap<X, int, X_hash>& s, X x)
 {
-  std::unordered_multimap<X, int>::iterator it = s.find(x);
+  std::unordered_multimap<X, int, X_hash>::iterator it = s.find(x);
   if (it != s.end())
     s.erase(it);
 }
index 4db6af0fa2593990bded93da114d58aa11e0aeb2..7a0a18352447650ce72f607f75a2d2211f94bec6 100644 (file)
@@ -27,12 +27,15 @@ struct X
   X(T&) {}
 };
 
+struct X_hash
+{ std::size_t operator()(const X&) const { return 0; } };
+
 bool operator==(const X&, const X&) { return false; }
 
 // LWG 2059.
-void erasor(std::unordered_multiset<X>& s, X x)
+void erasor(std::unordered_multiset<X, X_hash>& s, X x)
 {
-  std::unordered_multiset<X>::iterator it = s.find(x);
+  std::unordered_multiset<X, X_hash>::iterator it = s.find(x);
   if (it != s.end())
     s.erase(it);
 }
index 14864604289e8b81c938429f92793cd711d9d0fe..ec5aeb1a234ad057cc24dfbc6f92b3f4ba0d9db8 100644 (file)
@@ -27,12 +27,15 @@ struct X
   X(T&) {}
 };
 
+struct X_hash
+{ std::size_t operator()(const X&) const { return 0; } };
+
 bool operator==(const X&, const X&) { return false; }
 
 // LWG 2059.
-void erasor(std::unordered_set<X>& s, X x)
+void erasor(std::unordered_set<X, X_hash>& s, X x)
 {
-  std::unordered_set<X>::iterator it = s.find(x);
+  std::unordered_set<X, X_hash>::iterator it = s.find(x);
   if (it != s.end())
     s.erase(it);
 }