public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "relf at os2 dot ru" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/23633] New: map::insert() invalidates reverse_iterators
Date: Tue, 30 Aug 2005 13:01:00 -0000	[thread overview]
Message-ID: <20050830125045.23633.relf@os2.ru> (raw)

gcc (GCC) 4.0.2 20050821 (prerelease) (Debian 4.0.1-6)

In the following program inserting a new element into a map (i.e., M[2]=2)
invalidates an existing map::reverse_iterator im2. Before this insertion the
reverse_iterator im2 points to the pair (1,1), and after the insertion it
becomes erroneously pointing to the newly inserted pair (2,2).
There is no such problem with map::iterator m1.

Sample output:

before insertion:
im1->first = 1
im2->first = 1
after insertion:
im1->first = 1
im2->first = 2


#include <map>
#include <iostream>
using namespace std;

int main() {
    map<int,int> M;
    M[1] = 1;
    map<int,int>::iterator im1=M.begin();
    map<int,int>::reverse_iterator im2=M.rbegin();

    cout << "before insertion:" << endl;
    cout << "im1->first = " << im1->first << endl;
    cout << "im2->first = " << im2->first << endl;

    M[2] = 2;

    cout << "after insertion:" << endl;
    cout << "im1->first = " << im1->first << endl;
    cout << "im2->first = " << im2->first << endl;

    return 0;
}

-- 
           Summary: map::insert() invalidates reverse_iterators
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: relf at os2 dot ru
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23633


             reply	other threads:[~2005-08-30 12:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-30 13:01 relf at os2 dot ru [this message]
2005-08-30 14:15 ` [Bug libstdc++/23633] " pinskia at gcc dot gnu dot org
2005-08-30 15:49 ` chris at bubblescope dot net
2005-08-30 20:21 ` chris at bubblescope dot net
2005-08-31 10:13 ` pcarlini at suse dot de

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050830125045.23633.relf@os2.ru \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).