libstdc++/6791: hash_map: bad end() iterator

vograno@arbitrade.com vograno@arbitrade.com
Thu May 23 20:26:00 GMT 2002


>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:



More information about the Gcc-bugs mailing list