comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Got warnings when overriding Initialize and Finalize
Date: Fri, 10 Jul 2009 08:34:17 -0700 (PDT)
Date: 2009-07-10T08:34:17-07:00	[thread overview]
Message-ID: <16dc507c-4b96-4b53-b46f-2e806f988e6e@h18g2000yqj.googlegroups.com> (raw)
In-Reply-To: b10ebd28-794c-45aa-99ee-a56c51271d2f@d4g2000yqa.googlegroups.com

On Jul 10, 7:16 am, Hibou57 (Yannick Duchêne)
<yannick_duch...@yahoo.fr> 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
> >    type T is tagged limited private;
> > private
> >    type T is new Ada.Finalization.Limited_Controlled with null record;
> >    overriding procedure Initialize (Object : in out T);
> >    overriding procedure Finalize (Object : in out T);
> > end Test;
>
> This give me warnings like “ warning: declaration of "Initialize"
> hides one at line xxx ” where xxx is the line of “ type T is new
> Ada.Finalization.Limited_Controlled with null record; ”. The same
> warning appears for Finalize.
>
> If there is no more private part, there is no more warnings. Ex ...
>
> > with Ada.Finalization;
> >    type T is new Ada.Finalization.Limited_Controlled with null record;
> >    overriding procedure Initialize (Object : in out T);
> >    overriding 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
> >    type T is new Ada.Finalization.Limited_Controlled with private;
> >    overriding procedure Initialize (Object : in out T);
> >    overriding procedure Finalize (Object : in out T);
> > private
> >    type T is new Ada.Finalization.Limited_Controlled with null record;
> > 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
> >    type Dyn_String is private;
> >    Null_String : constant Dyn_String;
> >    ...
> > private
> >    type Dyn_String is new Ada.Finalization.Controlled with ...
> >    procedure Finalize(X : in out Dyn_String);
> >    procedure Adjust(X : in out Dyn_String);
>
> >    Null_String : constant Dyn_String :=
> >       (Ada.Finalization.Controlled with ...);
> >    ...
> > 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



  reply	other threads:[~2009-07-10 15:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-10 14:16 Got warnings when overriding Initialize and Finalize Hibou57 (Yannick Duchêne)
2009-07-10 15:34 ` Adam Beneschan [this message]
2009-07-10 16:12   ` Hibou57 (Yannick Duchêne)
2009-07-11  1:10   ` Randy Brukardt
2009-07-14 14:54     ` Robert A Duff
replies disabled

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