From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8e7f9bcdc1a5b9cd X-Google-Attributes: gid103376,public From: aklee@spam.this.interport.net (Albert K. Lee) Subject: Re: Seemingly wierd conversion for in out parameter Date: 1998/02/23 Message-ID: #1/1 X-Deja-AN: 327855039 References: Organization: Interport Communications Corp. Newsgroups: comp.lang.ada Date: 1998-02-23T00:00:00+00:00 List-Id: which version of GNAT were you using? On Fri, 20 Feb 1998 06:41:02 GMT, Corey Minyard 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