This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Wrong hastable key_eq implementation


Hi

I was quite surprise to discover this regression introduced by recent hashtable modifications.

2012-01-04 François Dumont <fdumont@gcc.gnu.org>

        * include/bits/hashtable_policy.h (_Hashtable_base<>::_M_eq()):
        protected rather than private, use it...
        * include/bits/hashtable.h (_Hashtable<>::key_eq()): ... here.
        * testsuite/23_containers/unordered_set/observers.cc: New.
        * testsuite/23_containers/unordered_multiset/observers.cc: New.
        * testsuite/23_containers/unordered_map/observers.cc: New.
        * testsuite/23_containers/unordered_multimap/observers.cc: New.


Tested under linux x86_64, ok to commit ?


If so and not done at that time, can I do the ChangeLog roll ?

I plan to do:
svn mv ChangeLog ChangeLog-2011
svn add ChangeLog

and move all 2012 entries to newly created ChangeLog.

Ok ?

François

Index: include/bits/hashtable.h
===================================================================
--- include/bits/hashtable.h	(revision 182856)
+++ include/bits/hashtable.h	(working copy)
@@ -371,7 +371,7 @@
       // Observers
       key_equal
       key_eq() const
-      { return this->_M_eq; }
+      { return this->_M_eq(); }
 
       // hash_function, if present, comes from _Hash_code_base.
 
Index: include/bits/hashtable_policy.h
===================================================================
--- include/bits/hashtable_policy.h	(revision 182857)
+++ include/bits/hashtable_policy.h	(working copy)
@@ -876,7 +876,7 @@
       std::swap(_M_eq(), __x._M_eq());
     }
 
-  private:
+  protected:
     const _Equal&
     _M_eq() const { return _EboEqual::_S_cget(*this); }
     _Equal&
Index: testsuite/23_containers/unordered_map/observers.cc
===================================================================
--- testsuite/23_containers/unordered_map/observers.cc	(revision 0)
+++ testsuite/23_containers/unordered_map/observers.cc	(revision 0)
@@ -0,0 +1,30 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2012 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 Pred 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/>.
+
+#include <unordered_map>
+
+void
+test01()
+{
+  std::unordered_map<int, int> um;
+
+  auto ke = um.key_eq();
+  auto h = um.hash_function();
+}
Index: testsuite/23_containers/unordered_multimap/observers.cc
===================================================================
--- testsuite/23_containers/unordered_multimap/observers.cc	(revision 0)
+++ testsuite/23_containers/unordered_multimap/observers.cc	(revision 0)
@@ -0,0 +1,30 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2012 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 Pred 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/>.
+
+#include <unordered_map>
+
+void
+test01()
+{
+  std::unordered_multimap<int, int> um;
+
+  auto ke = um.key_eq();
+  auto h = um.hash_function();
+}
Index: testsuite/23_containers/unordered_set/observers.cc
===================================================================
--- testsuite/23_containers/unordered_set/observers.cc	(revision 0)
+++ testsuite/23_containers/unordered_set/observers.cc	(revision 0)
@@ -0,0 +1,30 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2012 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 Pred 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/>.
+
+#include <unordered_set>
+
+void
+test01()
+{
+  std::unordered_set<int> us;
+
+  auto ke = us.key_eq();
+  auto h = us.hash_function();
+}
Index: testsuite/23_containers/unordered_multiset/observers.cc
===================================================================
--- testsuite/23_containers/unordered_multiset/observers.cc	(revision 0)
+++ testsuite/23_containers/unordered_multiset/observers.cc	(revision 0)
@@ -0,0 +1,30 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2012 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 Pred 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/>.
+
+#include <unordered_set>
+
+void
+test01()
+{
+  std::unordered_multiset<int> us;
+
+  auto ke = us.key_eq();
+  auto h = us.hash_function();
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]