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,ba1efd580c7c1290 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!r24g2000prf.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Dynamic allocation of unconstrained types Date: Wed, 30 Sep 2009 07:54:53 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1254322494 31566 127.0.0.1 (30 Sep 2009 14:54:54 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 30 Sep 2009 14:54:54 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: r24g2000prf.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8540 Date: 2009-09-30T07:54:53-07:00 List-Id: On Sep 30, 7:29=A0am, Maciej Sobczak wrote: > Consider: > > procedure Test is > > =A0 =A0package P is > =A0 =A0 =A0 type T (<>) is limited private; > =A0 =A0 =A0 function Create return T; > =A0 =A0private > =A0 =A0 =A0 type T is limited record > =A0 =A0 =A0 =A0 =A0I : Integer; > =A0 =A0 =A0 end record; > =A0 =A0end P; > > =A0 =A0package body P is > =A0 =A0 =A0 function Create return T is > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0return T'(I =3D> 123); > =A0 =A0 =A0 end Create; > =A0 =A0end P; > > =A0 =A0S : access P.T; > > begin > =A0 =A0S :=3D new P.T'(P.Create); =A0 -- ??? (this is line 22) > end Test; > > GNAT says: > > test.adb:22:19: uninitialized unconstrained allocation not allowed > test.adb:22:19: qualified expression required > > Interestingly, it works with Strings. > Why doesn't GNAT recognize it as a qualified expression? It looks like a bug to me. I do notice that if you remove "limited" from both declarations of T, then it works. There are some new Ada 2005 rules that allow limited-type expressions in more places (functions returning limited types weren't allowed in Ada 95), so it's likely that there was a mistake in implementing this new feature. > I would like to allocate dynamically something that has a constructor > function. There is no other way to create the object than with that > function and presumably it should be possible to use it with dynamic > allocation. > How can I do it? > > BTW - when preparing this example I tried first with empty (null) > record, but got stuck with proper way to return an instance of T. I > remember there was some older discussion about it, but for some reason > I cannot find it and the following: > > return T'(others =3D> <>); > > is rejected as well. Try return T'(null record); The first attempt, with (others =3D> <>), should have worked, but there was faulty language in the RM that made this illegal for a null record. It has been fixed by a Binding Interpretation, AI05-16, so I think compilers should allow that construct, but perhaps it hasn't yet been fixed in the version of GNAT you're using. -- Adam