From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Limited returns
Date: Mon, 23 Jun 2008 19:03:24 +0200
Date: 2008-06-23T19:03:28+02:00 [thread overview]
Message-ID: <umf8uvw0rac1.ocs4eq7gbyde.dlg@40tude.net> (raw)
In-Reply-To: 7ab69a86-cfcf-4dba-9280-e0fce906ed76@x1g2000prh.googlegroups.com
On Mon, 23 Jun 2008 08:15:12 -0700 (PDT), Adam Beneschan wrote:
> On Jun 23, 7:21 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> 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;
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2008-06-23 17:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-23 14:21 Limited returns Dmitry A. Kazakov
2008-06-23 15:04 ` fedya_fedyakoff
2008-06-23 15:20 ` fedya_fedyakoff
2008-06-23 16:53 ` Dmitry A. Kazakov
2008-06-24 10:56 ` fedya_fedyakoff
2008-06-24 13:51 ` Dmitry A. Kazakov
2008-06-24 15:01 ` fedya_fedyakoff
2008-06-24 16:31 ` Dmitry A. Kazakov
2008-06-24 16:42 ` Dmitry A. Kazakov
2008-06-23 15:49 ` Adam Beneschan
2008-06-24 10:13 ` fedya_fedyakoff
2008-06-23 15:15 ` Adam Beneschan
2008-06-23 17:03 ` Dmitry A. Kazakov [this message]
2008-06-23 18:15 ` Adam Beneschan
2008-06-23 19:44 ` Dmitry A. Kazakov
2008-06-26 12:35 ` Egil Høvik
2008-06-26 14:12 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox