public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/25896]  New: hash_map::erase, unordered_map::erase fail if key is inside the table
@ 2006-01-21  6:42 mec at google dot com
  2006-01-21  6:48 ` [Bug libstdc++/25896] " pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: mec at google dot com @ 2006-01-21  6:42 UTC (permalink / raw)
  To: gcc-bugs

This happens with both hash_map and unordered_map and their related classes.  I
know that hash_map is not standard, and unordered_map is in TR1 so not
considered standard yet.

Here is a kernel of the problem:

  hash_map<string,int> c;
  c.insert(...);
  hash_map<string,int>::iterator it = c.find("...");
  c.erase(it->first);

This is deleting by key value, not by iterator.

it->first is a key value which belongs to the collection object.
hash_map::erase(const key&) takes the key by reference.  It delegates to its
rep object, which is a hashtable.  hashtable::ref looks like this in gcc 4.0.2:

  if (__first)
    {
      ...
      while (__next)
        {
          if (_M_equals(_M_get_key(__next->_M_val), __key))
            {
              ...
              _M_delete_node(__next);
              ...
            }
          ...
        }
     ...
    }

The actual key object is in a node of the hash table.  After deleting that
node, the while() loop keeps using the deleted __key value with every other
node in the same bucket.

The following gcc versions have this problem with the following classes:

  gcc 3.4.5
    hash_map, hash_multimap, hash_set, hash_multiset

  gcc 4.0.2
  gcc 4.1-20060106
  gcc 4.2-20060114
    hash_map, hash_multimap, hash_set, hash_multiset
    unordered_map, unordered_multimap, unordered_set, unordered_multiset

You could punt on hash_map and friends because they are non-standard, but it is
nasty to have a case where code compiles and links and runs and then a library
function reads a destroyed object.  unordered_map and friends will eventually
(probably) be standardized so they are more serious.


-- 
           Summary: hash_map::erase, unordered_map::erase fail if key is
                    inside the table
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mec at google dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25896


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libstdc++/25896] hash_map::erase, unordered_map::erase fail if key is inside the table
  2006-01-21  6:42 [Bug libstdc++/25896] New: hash_map::erase, unordered_map::erase fail if key is inside the table mec at google dot com
@ 2006-01-21  6:48 ` pinskia at gcc dot gnu dot org
  2006-01-21  6:59 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-21  6:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-01-21 06:47 -------
I should note that TR1 is a written document.  I am wondering what it says
about this case.  If it says libstdc++ is right, then maybe you should try to
get it fixed (hard because I hear it is close to approval but I could be
wrong).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25896


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libstdc++/25896] hash_map::erase, unordered_map::erase fail if key is inside the table
  2006-01-21  6:42 [Bug libstdc++/25896] New: hash_map::erase, unordered_map::erase fail if key is inside the table mec at google dot com
  2006-01-21  6:48 ` [Bug libstdc++/25896] " pinskia at gcc dot gnu dot org
@ 2006-01-21  6:59 ` pinskia at gcc dot gnu dot org
  2006-01-21  7:21 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-21  6:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-01-21 06:59 -------
I should note that TR1 says erase does take the key by reference.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25896


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libstdc++/25896] hash_map::erase, unordered_map::erase fail if key is inside the table
  2006-01-21  6:42 [Bug libstdc++/25896] New: hash_map::erase, unordered_map::erase fail if key is inside the table mec at google dot com
  2006-01-21  6:48 ` [Bug libstdc++/25896] " pinskia at gcc dot gnu dot org
  2006-01-21  6:59 ` pinskia at gcc dot gnu dot org
@ 2006-01-21  7:21 ` pinskia at gcc dot gnu dot org
  2006-01-21 10:10 ` pcarlini at suse dot de
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-21  7:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2006-01-21 07:21 -------
"Erases all elements with key equivalent to k. Returns the number of elements
erased."
and then:
size_type erase(const key_type& k); 


So from that it might not be a bug in libstdc++ as far as I can see.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25896


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libstdc++/25896] hash_map::erase, unordered_map::erase fail if key is inside the table
  2006-01-21  6:42 [Bug libstdc++/25896] New: hash_map::erase, unordered_map::erase fail if key is inside the table mec at google dot com
                   ` (2 preceding siblings ...)
  2006-01-21  7:21 ` pinskia at gcc dot gnu dot org
@ 2006-01-21 10:10 ` pcarlini at suse dot de
  2006-01-21 10:11 ` pcarlini at suse dot de
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pcarlini at suse dot de @ 2006-01-21 10:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pcarlini at suse dot de  2006-01-21 10:10 -------
This is a general issue in the standard described in DR 526

  http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html

and prompted by libstdc++/17012 too. I guess the best we can do, is SUSPENDING
both the PRs and making sure DR 526 is discussed as soon as possible by the
LWG.


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-01-21 10:10:38
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25896


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libstdc++/25896] hash_map::erase, unordered_map::erase fail if key is inside the table
  2006-01-21  6:42 [Bug libstdc++/25896] New: hash_map::erase, unordered_map::erase fail if key is inside the table mec at google dot com
                   ` (3 preceding siblings ...)
  2006-01-21 10:10 ` pcarlini at suse dot de
@ 2006-01-21 10:11 ` pcarlini at suse dot de
  2007-02-22 19:29 ` [Bug libstdc++/25896] [DR 526] " pcarlini at suse dot de
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pcarlini at suse dot de @ 2006-01-21 10:11 UTC (permalink / raw)
  To: gcc-bugs



-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |SUSPENDED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25896


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libstdc++/25896] [DR 526] hash_map::erase, unordered_map::erase fail if key is inside the table
  2006-01-21  6:42 [Bug libstdc++/25896] New: hash_map::erase, unordered_map::erase fail if key is inside the table mec at google dot com
                   ` (4 preceding siblings ...)
  2006-01-21 10:11 ` pcarlini at suse dot de
@ 2007-02-22 19:29 ` pcarlini at suse dot de
  2007-02-23 23:34 ` paolo at gcc dot gnu dot org
  2007-02-23 23:35 ` pcarlini at suse dot de
  7 siblings, 0 replies; 9+ messages in thread
From: pcarlini at suse dot de @ 2007-02-22 19:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pcarlini at suse dot de  2007-02-22 19:29 -------
Now that we have a resolution for DR 526:

http://home.twcny.rr.com/hinnant/cpp_extensions/issues_preview/lwg-active.html#526

we can fix this problem too, similarly to like libstdc++/17012.


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |pcarlini at suse dot de
                   |dot org                     |
             Status|SUSPENDED                   |ASSIGNED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25896


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libstdc++/25896] [DR 526] hash_map::erase, unordered_map::erase fail if key is inside the table
  2006-01-21  6:42 [Bug libstdc++/25896] New: hash_map::erase, unordered_map::erase fail if key is inside the table mec at google dot com
                   ` (5 preceding siblings ...)
  2007-02-22 19:29 ` [Bug libstdc++/25896] [DR 526] " pcarlini at suse dot de
@ 2007-02-23 23:34 ` paolo at gcc dot gnu dot org
  2007-02-23 23:35 ` pcarlini at suse dot de
  7 siblings, 0 replies; 9+ messages in thread
From: paolo at gcc dot gnu dot org @ 2007-02-23 23:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from paolo at gcc dot gnu dot org  2007-02-23 23:34 -------
Subject: Bug 25896

Author: paolo
Date: Fri Feb 23 23:34:18 2007
New Revision: 122276

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122276
Log:
2007-02-23  Paolo Carlini  <pcarlini@suse.de>

        PR libstdc++/25896
        * include/tr1/hashtable (_Hashtable<>::erase(const key_type&)):
        Take care of &_M_extract((*__slot)->_M_v) == &__k.

        * testsuite/tr1/6_containers/unordered_map/erase/1.cc: New.
        * testsuite/tr1/6_containers/unordered_multimap/erase/1.cc: Likewise.
        * testsuite/tr1/6_containers/unordered_multiset/erase/1.cc: Likewise.
        * testsuite/tr1/6_containers/unordered_set/erase/1.cc: Likewise.

Added:
    trunk/libstdc++-v3/testsuite/tr1/6_containers/unordered_map/erase/1.cc
    trunk/libstdc++-v3/testsuite/tr1/6_containers/unordered_multimap/erase/1.cc
    trunk/libstdc++-v3/testsuite/tr1/6_containers/unordered_multiset/erase/1.cc
    trunk/libstdc++-v3/testsuite/tr1/6_containers/unordered_set/erase/1.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/tr1/hashtable


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25896


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libstdc++/25896] [DR 526] hash_map::erase, unordered_map::erase fail if key is inside the table
  2006-01-21  6:42 [Bug libstdc++/25896] New: hash_map::erase, unordered_map::erase fail if key is inside the table mec at google dot com
                   ` (6 preceding siblings ...)
  2007-02-23 23:34 ` paolo at gcc dot gnu dot org
@ 2007-02-23 23:35 ` pcarlini at suse dot de
  7 siblings, 0 replies; 9+ messages in thread
From: pcarlini at suse dot de @ 2007-02-23 23:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from pcarlini at suse dot de  2007-02-23 23:35 -------
Fixed.


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.3.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25896


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-02-23 23:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-21  6:42 [Bug libstdc++/25896] New: hash_map::erase, unordered_map::erase fail if key is inside the table mec at google dot com
2006-01-21  6:48 ` [Bug libstdc++/25896] " pinskia at gcc dot gnu dot org
2006-01-21  6:59 ` pinskia at gcc dot gnu dot org
2006-01-21  7:21 ` pinskia at gcc dot gnu dot org
2006-01-21 10:10 ` pcarlini at suse dot de
2006-01-21 10:11 ` pcarlini at suse dot de
2007-02-22 19:29 ` [Bug libstdc++/25896] [DR 526] " pcarlini at suse dot de
2007-02-23 23:34 ` paolo at gcc dot gnu dot org
2007-02-23 23:35 ` pcarlini at suse dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).