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!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Potential Coextension Bug in GNAT Date: Thu, 20 Dec 2018 20:25:40 -0600 Organization: JSA Research & Innovation Message-ID: References: Injection-Date: Fri, 21 Dec 2018 02:25:41 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="28110"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader01.eternal-september.org comp.lang.ada:55093 Date: 2018-12-20T20:25:40-06:00 List-Id: "Simon Wright" wrote in message news:lya7l0dqrw.fsf@pushface.org... > Jere writes: > >> with Ada.Text_IO; use Ada.Text_IO; >> with Ada.Finalization; use Ada.Finalization; >> >> procedure Hello is >> >> type Thing_1 is new Limited_Controlled with null record; >> >> overriding >> procedure Finalize(Self : in out Thing_1) is >> begin >> Put_Line("Finalize Thing_1"); >> end Finalize; >> >> type Thing_2 >> (Other : not null access Thing_1) >> is limited null record; >> >> procedure Test_Coextension_1 is >> The_Thing : Thing_2(new Thing_1); > > This is a case of 14.1/3, an allocator used to define the discriminant > of an object, Right, because 14.2/3 says "subtype_indication in any other context", meaning that 14.1/3 applies in an object declaration. >> begin >> Put_Line("Coextenson directly initialized"); >> end Test_Coextension_1; >> >> function Make_Thing_2 return Thing_2 is >> begin >> return (Other => new Thing_1); > > I think GNAT thinks this is a case of 14.2/3, an allocator used to > define the constraint in a subtype_indication, though I'm hard put to it > to see the difference from the first case. That doesn't make any sense, since 14.2/3 is talking about a syntactic subtype_indication, and there is no subtype_indication in the above aggregate. 14.2/3 would be talking about a case like: function Make_Thing_3 return Thing_2 is subtype Silly is Thing_2 (new Thing_1); Some_Thing : Silly; begin return Some_Thing; end Make_Thing_3; This function does NOT define a coextension. So it does look like a GNAT bug. There is the possibility that they are associating the discriminant with the temporary object associated with the allocator, and not the return object, but that seems unnecessarily unfriendly of an interpretation. And it would be wrong for any type that requires built-in-place (I didn't look at the actual declaration of the type). I think the rules are supposed to prevent that interpretation, but whether they really do is an interesting question that I have no interest in exploring. Randy. P.S. Did I mention I hate coextensions?? They provide an endless opportunity to puzzle over rules that really don't matter in the end (and most likely aren't quite right). I suppose they've helped me keep employed running the ARG. :-)