From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f2690a5e963b61b6 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!elnk-atl-nf1!newsfeed.earthlink.net!stamper.news.atl.earthlink.net!newsread3.news.atl.earthlink.net.POSTED!14bb18d8!not-for-mail Sender: mheaney@MHEANEYX200 Newsgroups: comp.lang.ada Subject: Re: GCC 4.0 Ada.Containers Cursor danger. References: <1120474891.635131.216700@g44g2000cwa.googlegroups.com> From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 16 Jul 2005 23:24:26 GMT NNTP-Posting-Host: 24.149.57.125 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.atl.earthlink.net 1121556266 24.149.57.125 (Sat, 16 Jul 2005 16:24:26 PDT) NNTP-Posting-Date: Sat, 16 Jul 2005 16:24:26 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: g2news1.google.com comp.lang.ada:3641 Date: 2005-07-16T23:24:26+00:00 List-Id: "Dmitriy Anisimkov" writes: > IMHO the cursors in the Ada.Containers implemented in GCC 4.0 > dangerouse like pointers in C/C++. > > Look at the code below. Here is a simplified version of your example: with Ada.Containers.Indefinite_Hashed_Maps; use Ada.Containers; with Ada.Strings.Hash; use Ada.Strings; procedure Test_HM is package Map_Types is new Indefinite_Hashed_Maps (String, Integer, Hash, "="); use Map_Types; M : Map; C, C2 : Cursor; B : Boolean; begin M.Insert ("one", 1); M.Insert ("two", 2, C, B); pragma Assert (B); M.Insert ("three", 3); pragma Assert (Has_Element (C)); pragma Assert (Key (C) = "two"); pragma Assert (Element (C) = 2); C2 := M.Find ("two"); pragma Assert (Has_Element (C2)); pragma Assert (Key (C) = "two"); pragma Assert (Element (C) = 2); M.Delete (C2); pragma Assert (not Has_Element (C2)); pragma Assert (not M.Contains ("two")); Replace_Element (C, -2); -- dangling cursor end Test_HM; When I compile it as follows (on WinXP): gnatmake -gnata -g -gnat05 test_hm and then run it, I get this output: raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : bad cursor in Replace_Element Does this behavior adequately satisfy your needs?