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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.182.103.194 with SMTP id fy2mr5347936obb.46.1438732585635; Tue, 04 Aug 2015 16:56:25 -0700 (PDT) X-Received: by 10.140.81.149 with SMTP id f21mr75679qgd.8.1438732585604; Tue, 04 Aug 2015 16:56:25 -0700 (PDT) Path: buffer1.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!f3no7617766igg.0!news-out.google.com!78ni6684qge.1!nntp.google.com!69no3924431qgl.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 4 Aug 2015 16:56:25 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=77.68.195.4; posting-account=X2aVgQoAAAC9R0AqSW-isDhmlPhqd7-0 NNTP-Posting-Host: 77.68.195.4 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0c1904af-8ede-4694-a50a-ac9f60d7dc63@googlegroups.com> Subject: Mutating elements of constant list using a container element iterator From: martinbbjerregaard@gmail.com Injection-Date: Tue, 04 Aug 2015 23:56:25 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: number.nntp.giganews.com comp.lang.ada:194667 Date: 2015-08-04T16:56:25-07:00 List-Id: Mutating elements of a constant container in a "for ... of ... loop" is possible with the "standard" container types but not the indefinite or bounded containers: with Ada.Containers.Doubly_Linked_Lists; with Ada.Containers.Indefinite_Doubly_Linked_Lists; procedure Strange_Behavior is type Test is tagged record Value : Integer; end record; package Test_Lists is new Ada.Containers.Doubly_Linked_Lists (Element_Type => Test); package Test_Indefinite_Lists is new Ada.Containers.Indefinite_Doubly_Linked_Lists (Element_Type => Test); function Make_List return Test_Lists.List is begin return Result : Test_Lists.List := Test_Lists.Empty_List do for I in 0 .. 100 loop Result.Append (Test'(Value => I)); end loop; end return; end Make_List; function Make_Indefinite_List return Test_Indefinite_Lists.List is begin return Result : Test_Indefinite_Lists.List := Test_Indefinite_Lists.Empty_List do for I in 0 .. 100 loop Result.Append (Test'(Value => I)); end loop; end return; end Make_Indefinite_List; V1 : constant Test_Lists.List := Make_List; V2 : constant Test_Indefinite_Lists.List := Make_Indefinite_List; begin for Item of V1 loop Item.Value := 0; -- no error end loop; for Item of V2 loop Item.Value := 0; -- error: "left hand side of assignment must be a variable" end loop; end Strange_Behavior; http://www.ada-auth.org/standards/12rat/html/Rat12-8-3.html says: "If we write for E of The_List loop ... -- do something to Element E end loop; then we can change the element E unless The_List has been declared as constant." Is this a bug?