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-7-bit Path: g2news2.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Dynamic allocation of unconstrained types Date: Wed, 30 Sep 2009 10:50:05 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1254322205 14721 192.74.137.71 (30 Sep 2009 14:50:05 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 30 Sep 2009 14:50:05 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:9V49aj75TenLuFB+OLUDZf/Ckis= Xref: g2news2.google.com comp.lang.ada:8539 Date: 2009-09-30T10:50:05-04:00 List-Id: Maciej Sobczak writes: > procedure Test is > > package P is > type T (<>) is limited private; > function Create return T; > private > type T is limited record > I : Integer; > end record; > end P; > > package body P is > function Create return T is > begin > return T'(I => 123); > end Create; > end P; > > S : access P.T; I try to avoid the use of anonymous access types. They cause too many surprises. > begin > S := new P.T'(P.Create); -- ??? (this is line 22) > end Test; > > GNAT says: > > test.adb:22:19: uninitialized unconstrained allocation not allowed > test.adb:22:19: qualified expression required Looks like a bug in the compiler. > Interestingly, it works with Strings. > Why doesn't GNAT recognize it as a qualified expression? > > 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 => <>); return (null record); or return T'(null record); The "others => <>" should work, too. > is rejected as well. > What is the proper way to create null aggregates? - Bob