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!.POSTED!not-for-mail From: "Alejandro R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: Is this actually possible? Date: Wed, 8 Apr 2020 18:10:39 +0200 Organization: A noiseless patient Spider Message-ID: References: <36d45c82-2a6b-4c60-baeb-1a4aef5189c7@googlegroups.com> <69c7677b-4aec-4db2-b240-de6b69f762b9@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 8 Apr 2020 16:10:40 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="3bb5fa1d4605ba1d898fc5536e57921f"; logging-data="31183"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1854HKavgcYM6Dh3cP4XUYJ" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 Cancel-Lock: sha1:ryTNN51L4UUwyfINX7fcgsKT+BE= In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:58327 Date: 2020-04-08T18:10:39+02:00 List-Id: I apologize for unearthing this old topic; I just came around to it. On 12/12/19 3:00, Randy Brukardt wrote: > This is the purpose of the Bounded_Indefinite_Holders, because this is a > useful thing to do sometimes. > > package My_Holders is new Ada.Containers.Bounded_Indefinite_Holders > (T'Class, 100); > > type An_Array is array (Positive range <>) of My_Holders.Holder; > > Here, a Holder will hold up to 100 storage units. If some extension of > T'Class is bigger than that, setting the holder to a value of that extension > raises Program_Error. (As with most checks, this one can be suppressed, and > if it would fail and is suppressed, the program is erroneous - presumably > some other object memory would be overwritten. So don't do that. ;-) > > This is probably one of the best (and simplest) ideas of Ada 202x. Thanks to > Niklas Holsti for the original idea (although I think the actual resulting > package isn't much like Niklas' original idea). I tried to use the GNAT CE 2019 Bounded_Holders once and got bitten by them being implemented with casts/address wizardry. This meant that storing controlled types and copying them while in bounded disguise broke finalization internals. (I don't remember the specifics, sorry). Is this an implementation allowance? I see note 13/5 at http://www.ada-auth.org/standards/2xrm/html/RM-A-18-32.html#I8180 that implies that Finalization should work. But then I also realize that the ARM package name is Bounded_Indefinite_Holders and not Bounded_Holders, so maybe the version I used is an early implementation. (This is what I have: https://github.com/gcc-mirror/gcc/blob/master/gcc/ada/libgnat/a-coboho.ads)