Bug#195388: libstdc++5-3.3-dev: erase()ing end() not harmless
Package: libstdc++5-3.3-dev
Version: 1:3.3-2
Severity: normal
...according to TC++PL 3rd ed, section 17.4.1.7,
"Erasing end() is harmless."
but the following code either hangs or crashes when the end() iterator
is being passed to erase();
*** set_erase.cc
#include <set>
#include <map>
#include <cassert>
int
main(int, char *[])
{
std::set<int> s;
s.insert (1); s.insert (2);
s.insert (1); s.insert (2);
assert (s.count (1) == 1);
assert (s.count (2) == 1);
s.erase (1);
assert (s.count (1) == 0); assert (s.find (1) == s.end ());
assert (s.count (2) == 1); assert (s.find (2) != s.end ());
s.erase (s.find (2));
assert (s.count (2) == 0); assert (s.find (2) == s.end ());
s.erase (s.find (2)); // fails
assert (s.count (2) == 0); assert (s.find (2) == s.end ());
std::map<int,int> m;
m[1] = 1;
m[2] = 2;
assert (m.count (2) != 0); assert (m.find (2) != m.end ());
m.erase (m.find (2));
assert (m.count (2) == 0); assert (m.find (2) == m.end ());
m.erase (m.find (2)); // fails
assert (m.count (2) == 0); assert (m.find (2) == m.end ());
}
-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux lfdux.ifs.tuwien.ac.at 2.4.20-1-k7 #1 Sat Mar 22 15:17:52 EST 2003 i686
Locale: LANG=C, LC_CTYPE=C
Versions of packages libstdc++5-3.3-dev depends on:
ii g++-3.3 1:3.3-2 The GNU C++ compiler
ii gcc-3.3-base 1:3.3-2 The GNU Compiler Collection (base
ii libc6-dev 2.3.1-17 GNU C Library: Development Librari
ii libstdc++5 1:3.3-2 The GNU Standard C++ Library v3
-- no debconf information
Reply to: