From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Lower bounds of Strings Date: Tue, 5 Jan 2021 14:40:19 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <1cc09f04-98f2-4ef3-ac84-9a9ca5aa3fd5n@googlegroups.com> NNTP-Posting-Host: 5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:61042 List-Id: On 2021-01-05 13:32, Jeffrey R. Carter wrote: > On 1/5/21 12:57 PM, Dmitry A. Kazakov wrote: >> >> This is a constraint, a meaningless and dangerous one: >> >>     procedure Foo (X : Mono_String); >>     S : String := "abcdefgh"; >> begin >>     Foo (S (2..S'Last)); -- Boom! Constraint_Error > > Surely the slice would slide, as it does in > > with Ada.Text_IO; > > procedure Slider is >    subtype S7 is String (1 .. 7); > >    procedure Foo (X : in S7); > >    procedure Foo (X : in S7) is >       -- Empty >    begin -- Foo >       Ada.Text_IO.Put (Item => X (7) ); >       Ada.Text_IO.New_Line; >    end Foo; > >    S : constant String := "abcdefgh"; > begin -- Slider >    Foo (X => S (2 .. 8) ); > end Slider; > > ~/Code$ gnatmake -gnatan -gnato2 -O2 -fstack-check slider.adb > x86_64-linux-gnu-gcc-9 -c -gnatan -gnato2 -O2 -fstack-check slider.adb > x86_64-linux-gnu-gnatbind-9 -x slider.ali > x86_64-linux-gnu-gnatlink-9 slider.ali -O2 -fstack-check > ~/Code$ ./slider > h Yes, but here S7 is definite, it is a quite different case. Sliding indefinite subtypes without copies, with access types allowed? And even with definite subtypes it is broken: with Ada.Text_IO; use Ada.Text_IO; procedure Main is subtype S7 is String (1..7); S : constant String := "abcdefgh"; V : S7 renames S (2..8); begin Put_Line ("Is it broken? " & Boolean'Image (S (7) = V (7))); end Main; This will print: Is it broken? TRUE -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de