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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC 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: Stephen Leake Subject: Re: Seemingly wierd conversion for in out parameter Date: 1998/02/26 Message-ID: <34F5B4D9.6F10@gsfc.nasa.gov>#1/1 X-Deja-AN: 328903730 Content-Transfer-Encoding: 7bit References: <6d02p0$r12$2@plug.news.pipex.net> <34F58B0B.6345@informatik.uni-stuttgart.de> Content-Type: text/plain; charset=us-ascii Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Mime-Version: 1.0 Reply-To: Stephen.Leake@gsfc.nasa.gov Newsgroups: comp.lang.ada Date: 1998-02-26T00:00:00+00:00 List-Id: Bernd Holzmueller wrote: > If no Ada rule is violated in the program presented by Corey Minyard, > they should perhaps be reconsidered as the following, slightly extended > program shows: > > 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 record X: Integer; end record; > type Der1_Class is access all Der1'Class; > > type Der2 is new Base with record Y: Float; end record; > type Der2_Class is access all Der2'Class; > > procedure Process (Var : in out Base_Class) is > begin > Var := new Der2'(Y => 3.45); > 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)); > > V1.X := 6; > > Process(Base_Class(V1)); > > Put_Line("V1 tag = " & Expanded_Name(V1'Tag)); > > Text_Io.Put_Line("V1.X = " & Integer'IMAGE(V1.X)); > > end Tester; > > This program outputs > > Base tag = TESTER.BASE > Der1 tag = TESTER.DER1 > Der2 tag = TESTER.DER2 > V1 tag = TESTER.DER1 > V1 tag = TESTER.DER2 > V1.X = 1079823565 > > and the last line of the output is a typical output of an uninitialized > variable > which is rather strange for a program that has all objects properly > initialized! Running this with ObjectAda 7.1 on Windows 95, we get Constraint_Error at the call " Process(Base_Class(V1)); ", which is expected since we are attempting to store a pointer to Der2 in a variable of type access Der1. GNAT 3.10p on Windows 95 does not raise Constraint_Error here, so I suspect it has a bug. What compiler are you using? please submit a bug report! -- - Stephe