comp.lang.ada
 help / color / mirror / Atom feed
From: Corey Minyard <minyard@acm.org>
Subject: Re: Seemingly wierd conversion for in out parameter
Date: 1998/02/23
Date: 1998-02-23T00:00:00+00:00	[thread overview]
Message-ID: <m2en0uvtoe.fsf@wf-rch.cirr.com> (raw)
In-Reply-To: slrn6f35im.gk0.aklee@interport.net


I'm using 3.11a1, but I really want to know if this is legal Ada95 or
a grey area.  If it is not legal, I'll report a bug to ACT.  If it is
a grey area, I won't use it.  If it is legal, I might use it.  I just
can't tell from the RM.

So again I'll ask...  Is this legal Ada95?

aklee@spam.this.interport.net (Albert K. Lee) writes:

> which version of GNAT were you using?
> 
> 
> On Fri, 20 Feb 1998 06:41:02 GMT, Corey Minyard <minyard@acm.org> wrote:
> >
> >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

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




  reply	other threads:[~1998-02-23  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
replies disabled

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