This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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]

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&pr=6791


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