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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,33ed4ca582c945fc X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!f24g2000prh.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Limited returns Date: Mon, 23 Jun 2008 11:15:23 -0700 (PDT) Organization: http://groups.google.com Message-ID: <0abe896d-2f42-43e6-8f8f-842dd5235950@f24g2000prh.googlegroups.com> References: <7ab69a86-cfcf-4dba-9280-e0fce906ed76@x1g2000prh.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1214244924 15646 127.0.0.1 (23 Jun 2008 18:15:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 23 Jun 2008 18:15:24 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f24g2000prh.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:827 Date: 2008-06-23T11:15:23-07:00 List-Id: On Jun 23, 10:03 am, "Dmitry A. Kazakov" wrote: > On Mon, 23 Jun 2008 08:15:12 -0700 (PDT), Adam Beneschan wrote: > > On Jun 23, 7:21 am, "Dmitry A. Kazakov" > > wrote: > >> Let's consider this: > > >> with Ada.Finalization; > >> procedure Test_Limited_Stuff is > >> type I is limited interface; > > >> type T is new Ada.Finalization.Limited_Controlled with record > >> A : Integer; > >> end record; > > >> type S is new T and I with record > >> Self : not null access S'Class := S'Unchecked_Access; > >> end record; > > >> function Factory return I'Class is > >> begin > >> return X : S; > >> -- GNAT: wrong type for return_subtype_indication > >> end Factory; > >> begin > >> null; > >> end Test_Limited_Stuff; > > >> Is it illegal? I am surprised why? S is in I'Class. > > > It's illegal, but hopefully not for long. See: > > >http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AI05s/AI05-0032-1.TXT?rev=1.4 > > It would be nice, because this "feature" is extremely boring. > > > Perhaps you could ask your compiler to go ahead and implement that AI > > (or at least the part of it that allows the specific return type as > > you've done). I think it was just an oversight in Ada 2005 not to > > allow this. > > Is there an AI to finally fix a similar problem with pool-specific access > types? I mean this: > > procedure Test_Access is > type T is tagged null record; > type S is new T with null record; > > type T_Ptr is access T'Class; > type S_Ptr is access S'Class; > > function Factory return T_Ptr is > X : S_Ptr := new S; > begin > .. -- Do something with X > return T_Ptr (X); -- Illegal!??? > end Factory; > begin > null; > end Test_Access; > > The only workaround is to cast: > > function Factory return T_Ptr is > Result : P_Ptr := new S; > X : S'Class renames S'Class (Result.all); > begin > .. -- Do something with X > return Result; > end Factory; I don't see an AI for this. I'm guessing that the problem would be that you could specify different pools for the two different access types, which would make the type conversion problematic (you'd have an access type object that points into the wrong pool, which could then cause havoc if you do an Unchecked_Deallocation). If the language rules said that a type conversion like this were allowed only if the storage pools were the same, the problem would then be that, since a storage pool rep clause could appear in the private part of a package, you could have a situation where you could not tell whether a type conversion was legal without peeking into the private part of a package you don't have visibility to. And that's something the language designers try very hard to avoid. On the other hand, if you're not going to specify a Storage_Pool for the types, is there a reason to make them pool-specific? I'm not sure what's gained by doing so. -- Adam