This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/34524] New: Use of invalidated std::string iterators not caught in debug mode
- From: "gcc-bugzilla at contacts dot eelis dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Dec 2007 19:43:03 -0000
- Subject: [Bug libstdc++/34524] New: Use of invalidated std::string iterators not caught in debug mode
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
In the following code, libstdc++'s debug mode does not catch the use of a
potentially invalidated std::string iterator.
#define _GLIBCXX_DEBUG
#define _GLIBCXX_DEBUG_PEDANTIC
#include <string>
#include <vector>
#include <iostream>
int main()
{
typedef std::string S;
S s (3, 'x');
S::iterator i = s.begin(); ++i;
s.push_back('y');
std::cout << *i << std::endl; // just outputs 'x'
}
Since the push_back may invalidate i (per 21.3 para 5, 4th item), libstdc++'s
debug mode should emit an error and abort.
If I change the typedef to std::vector<char>, then the indicated line /does/
cause libstdc++ to emit an error ("attempt to dereference a singular iterator")
and abort.
--
Summary: Use of invalidated std::string iterators not caught in
debug mode
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gcc-bugzilla at contacts dot eelis dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34524