comp.lang.ada
 help / color / mirror / Atom feed
From: matthew_heaney@acm.org (Matthew Heaney)
Subject: Generic Actual Tagged Objects Not Implicitly Aliased?
Date: 1998/04/29
Date: 1998-04-29T00:00:00+00:00	[thread overview]
Message-ID: <matthew_heaney-ya023680002904980053170001@news.ni.net> (raw)


Suppose we have the following tagged type:

type T is tagged limited ...;

When I pass an object of type T to a subprogram, it is implicitly aliased, ie

procedure Op (O : in out T) is
begin
   ... O'Access ...

Taking the 'Access of subprogram arg O is perfectly legal.

Now, suppose I have a generic declaration

generic
   O : in out T;
package GP is ...;

package body GP is

   .... O'Access ...


package Objects is

   O : T;

end;

with Objects;
package P is new GP (O);

My compiler (GNAT 3.10p) is telling me that that instantiation of P is
illegal, becuase O is not declared as aliased.

I can make the compiler happy by declaring O as aliased:

package Objects is

   O : aliased T;

end;

package P is new GP (O);

And now all is well.

This behavior begs certain questions:

1) Why can't you take the 'Access of generic formal object of a tagged
type, without the actual object being declared as aliased?  This would make
the behavior consistant with that for subprogram parameters.

2) Isn't this a contract violation?  Shouldn't the legality of the unit be
determined at the time of compilation of the generic?  How does the client
know he's supposed to declare the generic actual object as aliased, unless
he tries to compile the instantiation?  (This is redolent of the Ada 83
behavior for unconstrained generic actual types.)

3) Why can't you declare an "access" formal object, ie

generic
   O : access T;
package GP is ...;

At least this way it tells the client up front that the generic actual
object needs to be declared as aliased.

Thanks,
Matt




             reply	other threads:[~1998-04-29  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-04-29  0:00 Matthew Heaney [this message]
1998-04-29  0:00 ` Generic Actual Tagged Objects Not Implicitly Aliased? Tucker Taft
  -- strict thread matches above, loose matches on Subject: below --
1998-04-29  0:00 Matthew Heaney
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox