From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Private constant of tagged limited controlled type
Date: Sat, 22 Oct 2011 11:16:47 -0400
Date: 2011-10-22T11:16:47-04:00 [thread overview]
Message-ID: <wcclisd9huo.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: j7trtm$q5t$1@tornado.tornevall.net
Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:
> On 10/21/2011 11:14 PM, Malaise wrote:
>> The following complains that "initialization of limited object
>> requires aggregate or function call":
>
> Right.
>
>> with Ada.Finalization;
>> package Pack is
>> type T is tagged limited private;
>> C : constant T;
>> private
>> type T is new Ada.Finalization.Limited_Controlled with record
>> I : Integer := 0;
>> end record;
>> V : T;
>> C : constant T := V;
That's illegal, because you're trying to copy a limited object.
What if T had a self-referential component?
If the above were allowed, C.Self would incorrectly point
to V, not C. What if T contained a protected object?
It makes no sense to copy locks.
>> end Pack;
>> Aggregate seems impossible because Limited_Controlled is abstract and
>> anyway T is very complex in fact.
>
> I suggest you read ARM 4.3.1 and 4.3.2. You can write an aggregate of the form
>
> (Ada.Finalization.Limited_Controlled with others => <>)
Right, or:
C : constant T := (Ada.Finalization.Limited_Controlled with I => 123)
>> A function (returning tagged type) has to be visible and anyway cannot
>> return V (in Ada 2005).
>
> This is an unusual claim. The extended return statement was introduced
> specifically for returning limited types from a function. You ought to
> read ARM 6.5. You could write
>
> return X : T;
Right. Or it could say
return (Ada.Finalization.Limited_Controlled with others => <>);
But the comment, "cannot return V" is correct -- no matter whether
V is local or global.
> to return a value of T with all components set to their default values.
I also suggest reading this:
http://www.adacore.com/2007/09/24/ada-gem-10/
and also the following 2 gems, which I wrote to explain
how limited types work in Ada 2005.
- Bob
next prev parent reply other threads:[~2011-10-22 15:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-22 6:14 Private constant of tagged limited controlled type Malaise
2011-10-22 6:29 ` Jeffrey Carter
2011-10-22 15:16 ` Robert A Duff [this message]
2011-10-23 6:18 ` Malaise
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox