From: Adam Beneschan <adam@irvine.com>
Subject: Re: Dynamic allocation of unconstrained types
Date: Wed, 30 Sep 2009 07:54:53 -0700 (PDT)
Date: 2009-09-30T07:54:53-07:00 [thread overview]
Message-ID: <c736347a-8523-48d5-9f0c-03f9a9fbd1e6@r24g2000prf.googlegroups.com> (raw)
In-Reply-To: dd95bb9b-7604-4347-a964-2108502cf4c8@37g2000yqm.googlegroups.com
On Sep 30, 7:29 am, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
> Consider:
>
> 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;
>
> 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
>
> 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 => <>);
>
> is rejected as well.
Try
return T'(null record);
The first attempt, with (others => <>), 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
next prev parent reply other threads:[~2009-09-30 14:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-30 14:29 Dynamic allocation of unconstrained types Maciej Sobczak
2009-09-30 14:50 ` Robert A Duff
2009-09-30 14:54 ` Adam Beneschan [this message]
2009-09-30 18:30 ` Jeffrey R. Carter
2009-09-30 19:15 ` Adam Beneschan
2009-09-30 14:56 ` Dmitry A. Kazakov
2009-09-30 15:03 ` Adam Beneschan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox