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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: strange length check error Date: Wed, 17 Jan 2018 09:49:36 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <14a35359-150a-4aa6-b437-19c74381be4b@googlegroups.com> NNTP-Posting-Host: MyFhHs417jM9AgzRpXn7yg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.8.2 Xref: reader02.eternal-september.org comp.lang.ada:49950 Date: 2018-01-17T09:49:36+01:00 List-Id: On 16/01/2018 21:48, Mehdi Saada wrote: > This : Put(Ch_Bounded1 & ' ' ); > Calls on that: > function "&" > (Left : in Bounded_String; > Right : in Character) > return Bounded_String > is > begin > if LENGTH(LEFT) + 1 > MAX_LENGTH then > raise LENGTH_ERROR with "ERROR '&': LEFT.LENGTH := " & NATURAL'IMAGE(LENGTH(LEFT)) & " + 1 > MAX_LENGTH"; > else > @@@ return (LENGTH(LEFT) + 1, LEFT.DATA(1..LENGTH(LEFT)) & RIGHT); > end if; > end "&"; > > The line with @@@ raises this: > raised CONSTRAINT_ERROR : p_bounded_g-p_new_bounded_g.adb:34 length check failed > The value of CH_BOUNDED1 at that moment is "pour tester le debut", its length is 21, and MAX_LENGTH est 80. Why do you care? It is a wrong design anyway. The whole idea of bounded-length strings is avoid reallocation and copying upon string modification. [Which is why you should never use them] Thus, *all* operations on bounded-length strings must be in-place, except constructors. If you have "&" that defeats the only purpose of having such strings. Use String. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de