comp.lang.ada
 help / color / mirror / Atom feed
* Generic Actual Tagged Objects Not Implicitly Aliased?
@ 1998-04-29  0:00 Matthew Heaney
  0 siblings, 0 replies; 3+ messages in thread
From: Matthew Heaney @ 1998-04-29  0:00 UTC (permalink / 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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Generic Actual Tagged Objects Not Implicitly Aliased?
@ 1998-04-29  0:00 Matthew Heaney
  1998-04-29  0:00 ` Tucker Taft
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Heaney @ 1998-04-29  0:00 UTC (permalink / 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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Generic Actual Tagged Objects Not Implicitly Aliased?
  1998-04-29  0:00 Matthew Heaney
@ 1998-04-29  0:00 ` Tucker Taft
  0 siblings, 0 replies; 3+ messages in thread
From: Tucker Taft @ 1998-04-29  0:00 UTC (permalink / raw)



Matthew Heaney (matthew_heaney@acm.org) wrote:

: Suppose we have the following tagged type:

: type T is tagged limited ...;

: ...
: 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.

This sounds like a bug in GNAT.

: ...
: 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.

You can.  Don't confuse bugs in an implementation with bugs
in the language definition ;-).

: ...
: Thanks,
: Matt

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-04-29  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-29  0:00 Generic Actual Tagged Objects Not Implicitly Aliased? Matthew Heaney
  -- strict thread matches above, loose matches on Subject: below --
1998-04-29  0:00 Matthew Heaney
1998-04-29  0:00 ` Tucker Taft

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