comp.lang.ada
 help / color / mirror / Atom feed
* Seemingly wierd conversion for in out parameter
@ 1998-02-20  0:00 Corey Minyard
  1998-02-23  0:00 ` Albert K. Lee
  0 siblings, 1 reply; 7+ messages in thread
From: Corey Minyard @ 1998-02-20  0:00 UTC (permalink / raw)




I've been playing with some techniques with derived types and I ran
across a rather unusual things.  The following program:

with Text_IO; use Text_IO;
with Ada.Tags; use Ada.Tags;

------------------------------------------------------------------------
procedure Tester is

   type Base is abstract tagged null record;
   type Base_Class is access all Base'Class;

   type Der1 is new Base with null record;
   type Der1_Class is access all Der1'Class;

   type Der2 is new Base with null record;
   type Der2_Class is access all Der2'Class;

   procedure Process (Var : in out Base_Class) is
   begin
      Var := new Der2;
   end Process;

   V1 : Der1_Class := new Der1;
-- This will be a compile error.
--   U1 : Der1_Class := new Der2;

begin

   Put_Line("Base tag = " & Expanded_Name(Base'Tag));
   Put_Line("Der1 tag = " & Expanded_Name(Der1'Tag));
   Put_Line("Der2 tag = " & Expanded_Name(Der2'Tag));

   Put_Line("V1 tag = " &  Expanded_Name(V1'Tag));

   Process(Base_Class(V1));

   Put_Line("V1 tag = " &  Expanded_Name(V1'Tag));

end Tester;
------------------------------------------------------------------------

will compile and produce the following output:

------------------------------------------------------------------------
Base tag = TESTER.BASE
Der1 tag = TESTER.DER1
Der2 tag = TESTER.DER2
V1 tag = TESTER.DER1
V1 tag = TESTER.DER2
------------------------------------------------------------------------

As you can see, the variable V1 should not be able to reference a
tagged type of Der2, but this program does that without any errors
under GNAT (the only compiler I have right now).  I would think that
the compiler wouldn't allow a class conversion passed to an in out
parameter, but it seems to.

I'm certainly no language lawyer, but I would image that doing a cast
would make something not a "variable" any more (RM 6.4.1(5)), thus
this would not be legal.  Is GNAT wrong, or is this legal, or is this
a grey area?

Thanks,

-- 
Corey Minyard               Internet:  minyard@acm.org
  Work: minyard@nortel.ca       UUCP:  minyard@wf-rch.cirr.com




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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-02-20  0:00 Seemingly wierd conversion for in out parameter Corey Minyard
1998-02-23  0:00 ` Albert K. Lee
1998-02-23  0:00   ` Corey Minyard
1998-02-25  0:00     ` Nick Roberts
1998-02-26  0:00       ` Bernd Holzmueller
1998-02-26  0:00         ` Stephen Leake
1998-02-26  0:00           ` Robert Dewar

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