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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,CP1252 Path: g2news2.google.com!postnews.google.com!h18g2000yqj.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Got warnings when overriding Initialize and Finalize Date: Fri, 10 Jul 2009 08:34:17 -0700 (PDT) Organization: http://groups.google.com Message-ID: <16dc507c-4b96-4b53-b46f-2e806f988e6e@h18g2000yqj.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1247240057 5858 127.0.0.1 (10 Jul 2009 15:34:17 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 10 Jul 2009 15:34:17 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h18g2000yqj.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6944 Date: 2009-07-10T08:34:17-07:00 List-Id: On Jul 10, 7:16=A0am, Hibou57 (Yannick Duch=EAne) wrote: > Hello, > > I got some warnings which still stick to me when I want to override > Initialize and Finalize on controlled types. > > Here is a reduced example of the matter : > > > with Ada.Finalization; > > package Test is > > =A0 =A0type T is tagged limited private; > > private > > =A0 =A0type T is new Ada.Finalization.Limited_Controlled with null reco= rd; > > =A0 =A0overriding procedure Initialize (Object : in out T); > > =A0 =A0overriding procedure Finalize (Object : in out T); > > end Test; > > This give me warnings like =93 warning: declaration of "Initialize" > hides one at line xxx =94 where xxx is the line of =93 type T is new > Ada.Finalization.Limited_Controlled with null record; =94. The same > warning appears for Finalize. > > If there is no more private part, there is no more warnings. Ex ... > > > with Ada.Finalization; > > =A0 =A0type T is new Ada.Finalization.Limited_Controlled with null reco= rd; > > =A0 =A0overriding procedure Initialize (Object : in out T); > > =A0 =A0overriding procedure Finalize (Object : in out T); > > end Test; > > ... does not produce any warnings. > > If I do the following, there is no warning as well : > > > with Ada.Finalization; > > package Test is > > =A0 =A0type T is new Ada.Finalization.Limited_Controlled with private; > > =A0 =A0overriding procedure Initialize (Object : in out T); > > =A0 =A0overriding procedure Finalize (Object : in out T); > > private > > =A0 =A0type T is new Ada.Finalization.Limited_Controlled with null reco= rd; > > end Test; > > Is it mandatory to declare overriding of Initialize and Finalize in > the public part and thus to declare the T is an > Ada.Finalization.Limited_Controlled in the public part as well ? > > But the Annotated RM contains this small excerpt : > > AARM 7.6 17.h.2/1 says: > > > package P is > > =A0 =A0type Dyn_String is private; > > =A0 =A0Null_String : constant Dyn_String; > > =A0 =A0... > > private > > =A0 =A0type Dyn_String is new Ada.Finalization.Controlled with ... > > =A0 =A0procedure Finalize(X : in out Dyn_String); > > =A0 =A0procedure Adjust(X : in out Dyn_String); > > > =A0 =A0Null_String : constant Dyn_String :=3D > > =A0 =A0 =A0 (Ada.Finalization.Controlled with ...); > > =A0 =A0... > > end P; > > So what to think about these warnings ? > > Is there something I am not seeing ? This looks like a compiler glitch to me. There is a case, involving *untagged* types, where overriding an operation in the private part can lead to some unexpected results: package Pak2 is type T2 is new Pak1.T; -- inherits operation Op private overriding procedure Op (X : T2); end Pak2; Now, calling Op on an object of type T2 may give you either the inherited one or the overriding one, depending on whether the private part of Pak2 is visible at that point. It may be that the compiler, with this case in mind, displays a warning any time there's an override in the private part of a package; but it seems like it's going overboard in this case. The compiler needs to tailor its warnings a little better. That's just my guess as to why you're seeing the warnings. But there isn't anything wrong with your original code. -- Adam