comp.lang.ada
 help / color / mirror / Atom feed
From: jgv@swl.msd.ray.com (John Volan)
Subject: Re: Overloading for T and T'Class
Date: Wed, 16 Nov 1994 01:22:35 GMT
Date: 1994-11-16T01:22:35+00:00	[thread overview]
Message-ID: <CzC6Ho.Lqn@swlvx2.msd.ray.com> (raw)
In-Reply-To: Cz4H8G.MA@swlvx2.msd.ray.com

In article <Cz4H8G.MA@swlvx2.msd.ray.com> jgv@swl.msd.ray.com (John Volan) writes:

> In Ada9X, is it legal to overload the same subprogram name for both
>some tagged type T and its class-wide type T'Class?  For example:
>
>	package P is
>	  type T is tagged ... ;
>	  procedure Op (X : in out T);
>	  procedure Op (X : in out T'Class);
>	  ...
>	end P;
>
>If this is legal, what would be the ramifications of doing this?
>Would it even make any sense to do this?  If it did make sense, does
>anyone have any thoughts as to where this might turn out to be useful?

Thanks to those who sent me private e-mail on this.  Summarizing the
responses so far: Yes, this does appear to be legal according to the
current definition of Ada9X.  Apparently, T and T'Class are considered
to be different types, even though the set of values of type T'Class
"covers" the set of values of type T.  That's pretty much what I
figured.

However, doing this might cause overload resolution problems when you
make an invocation:

	with P;
	procedure P_Client (X: in out P.T) is
	begin
	  ...
	  P.Op (X); -- Error in overload resolution -- ambiguous.
	  ...
	  P.Op (P.T'(X));  -- Although maybe these would work?
	  P.Op (P.T'Class'(X));
	  ...
	end P_Client;

On the other hand, the following doesn't appear to be ambiguous:

	with P;
	procedure Another_P_Client (X: in out P.T'Class) is
	begin
	  ...
	  P.Op (X); -- No problem, only one way to interpret this
	  ...
	end Another_P_Client;

(FYI: GNAT-1.83 seems to like the package spec P, but dies with an
assertion failure on an attempt to invoke.  (Bug report has been
filed.)  Anyway, it would be nice to get some human confirmation on
this.  Tucker, you have the last word: Is this legal?)

The other half of my question was whether there was any rationale
anyone could suggest for actually making use of this kind of
overloading.  Personally, I haven't been able to come up with one.  On
the basis of the ambiguous-invocation problem alone, I'd say that we'd
probably want to avoid doing overloadings like these.  But does anyone
else have any thoughts on this?

					John Volan

--------------------------------------------------------------------------------
--  Me : Person := (Name                => "John Volan",
--                  Company             => "Raytheon Missile Systems Division",
--                  E_Mail_Address      => "jgv@swl.msd.ray.com",
--                  Affiliation         => "Enthusiastic member of Team Ada!",
--                  Humorous_Disclaimer => "These opinions are undefined " &
--                                         "by my employer and therefore " &
--                                         "any use of them would be "     &
--                                         "totally erroneous.");
--------------------------------------------------------------------------------








  parent reply	other threads:[~1994-11-16  1:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-11-11 21:33 Overloading for T and T'Class John Volan
1994-11-14  2:07 ` David Weller
1994-11-15  5:01   ` Cyrille Comar
1994-11-15  2:22 ` Bob Duff
1994-11-16 11:33   ` Robert I. Eachus
     [not found] ` <3a6goo$j7s@starbase.neosoft.com>
1994-11-15  2:35   ` Tucker Taft
1994-11-15 11:39     ` David Weller
1994-11-16  4:32       ` Brad Balfour
1994-11-16 14:34         ` John Volan
1994-11-15 14:15     ` Norman H. Cohen
1994-11-16  1:22 ` John Volan [this message]
1994-11-16 11:59   ` David Weller
1994-11-19  4:54   ` Cyrille Comar
replies disabled

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