public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* libstdc++/6791: hash_map: bad end() iterator
@ 2002-05-23 20:26 vograno
  0 siblings, 0 replies; 3+ messages in thread
From: vograno @ 2002-05-23 20:26 UTC (permalink / raw)
  To: gcc-gnats


>Number:         6791
>Category:       libstdc++
>Synopsis:       hash_map: bad end() iterator
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May 23 20:26:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Vadim Ogranovich
>Release:        gcc version 3.0.4
>Organization:
>Environment:
Linux
>Description:
The following program produces a segmentation fault. It works fine if map is used instead of hash_map.
Note also that a number of calls to the destructor ~Foo() exceeds the number of constructor calls (not a bug per se, but looks strage).

//file foo.cpp
#include <iostream>
#include <map>
#include <ext/hash_map>

using namespace std;


class Foo {
public:
  Foo() {
    cerr << "constructed\n";
  }

  ~Foo() {
    cerr << "destructed\n";
  }
};

typedef  hash_map<int, Foo> HT;

int main()
{
  HT fooH;
  fooH[0] = Foo();

  for (HT::iterator iter=fooH.begin(); iter!=fooH.end(); ++iter) {
    cerr << "erasing\n";
    fooH.erase(iter);
  }

  return 0;
}
>How-To-Repeat:
save to foo.cpp
compile: g++ -g   foo.cpp -o foo
run: ./foo
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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

* RE: libstdc++/6791: hash_map: bad end() iterator
@ 2002-05-24 11:36 Vadim Ogranovich
  0 siblings, 0 replies; 3+ messages in thread
From: Vadim Ogranovich @ 2002-05-24 11:36 UTC (permalink / raw)
  To: paolo; +Cc: gcc-prs

The following reply was made to PR libstdc++/6791; it has been noted by GNATS.

From: Vadim Ogranovich <vograno@arbitrade.com>
To: "'paolo@gcc.gnu.org'" <paolo@gcc.gnu.org>,
   
	  "'gcc-bugs@gcc.gnu.org'"<gcc-bugs@gcc.gnu.org>,
   "'gcc-prs@gcc.gnu.org'" <gcc-prs@gcc.gnu.org>,
   "'nobody@gcc.gnu.org'" <nobody@gcc.gnu.org>,
   
	  "'paolo@gcc.gnu.org'"<paolo@gcc.gnu.org>,
    "'gcc-gnats@gcc.gnu.org'" <gcc-gnats@gcc.gnu.org>
Cc:  
Subject: RE: libstdc++/6791: hash_map: bad end() iterator
Date: Fri, 24 May 2002 13:30:29 -0500

 Sorry for the false report. Thank you for the explanations, Vadim
 
 -----Original Message-----
 From: paolo@gcc.gnu.org [mailto:paolo@gcc.gnu.org]
 Sent: Friday, May 24, 2002 10:37 AM
 To: gcc-bugs@gcc.gnu.org; gcc-prs@gcc.gnu.org; nobody@gcc.gnu.org;
 paolo@gcc.gnu.org; vograno@arbitrade.com
 Subject: Re: libstdc++/6791: hash_map: bad end() iterator
 
 
 Synopsis: hash_map: bad end() iterator
 
 Responsible-Changed-From-To: unassigned->paolo
 Responsible-Changed-By: paolo
 Responsible-Changed-When: Fri May 24 10:36:38 2002
 Responsible-Changed-Why:
     Triaged.
 State-Changed-From-To: open->closed
 State-Changed-By: paolo
 State-Changed-When: Fri May 24 10:36:38 2002
 State-Changed-Why:
     User error. See Josuttis pp. 204-205 for a clear
     explanation of why this is, in general, an incorrect use
     of erase() (it works for map only "by chance"). In a
     nutshell, fooH.erase(iter) invalidates iter as an iterator
     of HT and the following ++iter results in undefined
     behavior. The correct way is the following:
     ...
       for (HT::iterator iter=fooH.begin(); iter!=fooH.end();) {
         cerr << "erasing\n";
         fooH.erase(iter++);
       }
     ...
     Thanks for your report, Paolo.
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p
 r=6791
 
 -------------------------------------------------- 
 DISCLAIMER 
 This e-mail, and any attachments thereto, is intended only for use by the
 addressee(s) named herein and may contain legally privileged and/or
 confidential information.  If you are not the intended recipient of this
 e-mail, you are hereby notified that any dissemination, distribution or
 copying of this e-mail, and any attachments thereto, is strictly prohibited.
 If you have received this e-mail in error, please immediately notify me and
 permanently delete the original and any copy of any e-mail and any printout
 thereof. 
 
 E-mail transmission cannot be guaranteed to be secure or error-free.  The
 sender therefore does not accept liability for any errors or omissions in
 the contents of this message which arise as a result of e-mail transmission.
 
 NOTICE REGARDING PRIVACY AND CONFIDENTIALITY 
 
 Knight Trading Group may, at its discretion, monitor and review the content
 of all e-mail communications. 
 


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

* Re: libstdc++/6791: hash_map: bad end() iterator
@ 2002-05-24 10:46 paolo
  0 siblings, 0 replies; 3+ messages in thread
From: paolo @ 2002-05-24 10:46 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, paolo, vograno

Synopsis: hash_map: bad end() iterator

Responsible-Changed-From-To: unassigned->paolo
Responsible-Changed-By: paolo
Responsible-Changed-When: Fri May 24 10:36:38 2002
Responsible-Changed-Why:
    Triaged.
State-Changed-From-To: open->closed
State-Changed-By: paolo
State-Changed-When: Fri May 24 10:36:38 2002
State-Changed-Why:
    User error. See Josuttis pp. 204-205 for a clear
    explanation of why this is, in general, an incorrect use
    of erase() (it works for map only "by chance"). In a
    nutshell, fooH.erase(iter) invalidates iter as an iterator
    of HT and the following ++iter results in undefined
    behavior. The correct way is the following:
    ...
      for (HT::iterator iter=fooH.begin(); iter!=fooH.end();) {
        cerr << "erasing\n";
        fooH.erase(iter++);
      }
    ...
    Thanks for your report, Paolo.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6791


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

end of thread, other threads:[~2002-05-24 18:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-23 20:26 libstdc++/6791: hash_map: bad end() iterator vograno
2002-05-24 10:46 paolo
2002-05-24 11:36 Vadim Ogranovich

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).