This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/10794: std::map's erase method invalidates reverse_iterators
- From: gandy at abacho dot de
- To: gcc-gnats at gcc dot gnu dot org
- Date: 14 May 2003 23:45:16 -0000
- Subject: libstdc++/10794: std::map's erase method invalidates reverse_iterators
- Reply-to: gandy at abacho dot de
>Number: 10794
>Category: libstdc++
>Synopsis: std::map's erase method invalidates reverse_iterators
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed May 14 23:46:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: gandy@abacho.de
>Release: libstdc++5-3.3
>Organization:
>Environment:
debian linux:
ii libstdc++5 3.3-0pre9
ii libstdc++5-3.3-dev 3.3-0pre9
ii libstdc++5-3.3-doc 3.3-0pre9
ii libstdc++5-dev 3.2.3-2
ii g++ 3.2.3-1
ii g++-3.2 3.2.3-2
ii g++-3.3 3.3-0pre9
>Description:
Programm output (g++-3.2 and g++-3.3):
-90
270
-90
-90
Expected output:
-90
-90
-90
-90
Note that the reverse_iterator jt is NOT pointing to the element which is erased.
Citation from SGI STL Docu:
Erasing an element from a map also does not invalidate any iterators, except, of course, for iterators that actually point to the element that is being erased.
I would think that applies to reverse_iterators, too.
>How-To-Repeat:
#include <iostream>
#include <map>
using namespace std;
int main()
{
map<double, double> byloc;
map<double, double>::reverse_iterator jt;
byloc.insert(pair<double, double>(90, 1));
byloc.insert(pair<double, double>(-90, 1));
byloc.insert(pair<double, double>(270, 1));
byloc.insert(pair<double, double>(-270, 1));
jt = byloc.rbegin();
jt++;
jt++;
cout << jt->first << endl;
byloc.erase(90);
cout << jt->first << endl;
byloc.clear();
byloc.insert(pair<double, double>(90, 1));
byloc.insert(pair<double, double>(-90, 1));
byloc.insert(pair<double, double>(270, 1));
jt = byloc.rbegin();
jt++;
jt++;
cout << jt->first << endl;
byloc.erase(90);
cout << jt->first << endl;
return 0;
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: