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: a07f3367d7,735c710b5e547bad X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.223.40 with SMTP id qr8mr2775866pbc.0.1342108086152; Thu, 12 Jul 2012 08:48:06 -0700 (PDT) Path: l9ni11564pbj.0!nntp.google.com!news1.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Ada 2005 puzzle Date: Thu, 12 Jul 2012 08:48:05 -0700 (PDT) Organization: http://groups.google.com Message-ID: <030cde76-7435-405d-9f12-ac7f730ecab8@googlegroups.com> References: <1arp60wtxes8h$.1qs6bt732ztgp.dlg@40tude.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1342108086 8623 127.0.0.1 (12 Jul 2012 15:48:06 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 12 Jul 2012 15:48:06 +0000 (UTC) In-Reply-To: <1arp60wtxes8h$.1qs6bt732ztgp.dlg@40tude.net> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-07-12T08:48:05-07:00 List-Id: On Thursday, July 12, 2012 5:54:08 AM UTC-7, Dmitry A. Kazakov wrote: > Here is a simplified case illustrating an issue with constructing functio= ns > and limited aggregates: >=20 > -------------------------------------------- package P > with Ada.Finalization; > package P is > type T (<>) is new Ada.Finalization.Limited_Controlled with private; > function Create return T; > private > type T is new Ada.Finalization.Limited_Controlled with null record; > end P; > - - - - - - - - - - - - - - - - - - - - - - - -=20 > package body P is > function Create return T is > begin > return (Ada.Finalization.Limited_Controlled with null record); > end Create; > end P; > -------------------------------------------- package Q > with P; use P; > package Q is > type S is abstract new T with null record; > type R is new S with null record; > overriding function Create return R; > end Q; > - - - - - - - - - - - - - - - - - - - - - - - -=20 > package body Q is > function Create return R is > begin > return (T'(Create) with null record); -- Error! > end Create; > end Q; >=20 > Is there a way to implement Create (without compromising the package P)? Well, there seem to be a couple bogus things about your example: (1) your e= xtension aggregate in Q doesn't have any additional components, and (2) the= title of your post is "Ada 2005 puzzle". I'm guessing that the error is s= upposed to refer to 4.3.2(5.1ff), which puts some restrictions on when the = ancestor part of an extension aggregate can be a function call whose return= subtype is an unconstrained subtype. (T is unconstrained because it is de= clared with (<>).) However, those restrictions only apply only if the rest= of the aggregate needs at least one component (and yours doesn't). Furthe= rmore, the restrictions were added in Ada 2012, so this shouldn't have been= illegal in Ada 2005 even if there were another component. So I think ther= e's a compiler bug. I can't find another reason why the above example woul= d be illegal. However, if you were to make R (or S) a type extension with at least one ne= w component, rather than a null extension, there would be a problem. This = was made illegal because in the private part of P, you *could* define T lik= e this: type T (D : Positive) is new Ada.Finalization.Limited_Controlled with re= cord Name : String (1 .. D); end record; and now the size of T would depend on the discriminant. Since the extensio= n aggregate has to be built in place (no copying allowed, since this is a l= imited type), this means that the caller (in Q) has to reserve an unknown a= mount of space for the ancestor part of the aggregate before it calls P.Cre= ate to fill in that space. Or something like that. I haven't really studi= ed all the details of the problem, but it does appear that there's a major = implementation difficulty. See=20 http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai05s/ai05-0067-1.txt?rev=3D1.18 for a discussion of the problem. (Yes, I know that it isn't a problem in y= our case because the full definition of T doesn't have discriminants. But = the language rules about what's legal and what isn't aren't supposed to dep= end on private parts that aren't visible.) I'm guessing that if you really want this to work in a case where T has a v= arying size, it's just asking too much. It's not feasible to implement, ap= parently. However, if you want to declare T with unknown discriminants in = the visible part, but the intent is that the full declaration of T has a fi= xed size, then perhaps this could be solved with a language change that let= s you put a "Fixed_Size" aspect on the first declaration of T. That would = make it illegal for the full declaration of T to contain anything that woul= d make its size variable, and it could mean that the rule in 4.3.2(5.1ff) w= ouldn't have to apply. If this is a real issue (and not simply a hypothet= ical one), then maybe ARG would be open to a proposed change like this. =20 Hope this helps, but please keep in mind that I don't fully understand the = issues involved because I haven't studied them carefully. -- Adam