comp.lang.ada
 help / color / mirror / Atom feed
* Got warnings when overriding Initialize and Finalize
@ 2009-07-10 14:16 Hibou57 (Yannick Duchêne)
  2009-07-10 15:34 ` Adam Beneschan
  0 siblings, 1 reply; 5+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2009-07-10 14:16 UTC (permalink / raw)


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 ?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Got warnings when overriding Initialize and Finalize
  2009-07-10 14:16 Got warnings when overriding Initialize and Finalize Hibou57 (Yannick Duchêne)
@ 2009-07-10 15:34 ` Adam Beneschan
  2009-07-10 16:12   ` Hibou57 (Yannick Duchêne)
  2009-07-11  1:10   ` Randy Brukardt
  0 siblings, 2 replies; 5+ messages in thread
From: Adam Beneschan @ 2009-07-10 15:34 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Got warnings when overriding Initialize and Finalize
  2009-07-10 15:34 ` Adam Beneschan
@ 2009-07-10 16:12   ` Hibou57 (Yannick Duchêne)
  2009-07-11  1:10   ` Randy Brukardt
  1 sibling, 0 replies; 5+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2009-07-10 16:12 UTC (permalink / raw)


On 10 juil, 17:34, Adam Beneschan <a...@irvine.com> wrote:
> 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.
Indeed, this example is a bad practice

> 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
.... and it does not take care it is a tagged type so

Your idea of the reason why is clever



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Got warnings when overriding Initialize and Finalize
  2009-07-10 15:34 ` Adam Beneschan
  2009-07-10 16:12   ` Hibou57 (Yannick Duchêne)
@ 2009-07-11  1:10   ` Randy Brukardt
  2009-07-14 14:54     ` Robert A Duff
  1 sibling, 1 reply; 5+ messages in thread
From: Randy Brukardt @ 2009-07-11  1:10 UTC (permalink / raw)


"Adam Beneschan" <adam@irvine.com> wrote in message 
news:16dc507c-4b96-4b53-b46f-2e806f988e6e@h18g2000yqj.googlegroups.com...
...
> 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.

For the record, I agree with Adam. Claw is full of overridings like this; 
our rule was that overridings should be done in the private part as there is 
no reason for the client to know whether the routines are overridden or just 
inherited. Looks like a bogus warning to me (and Adam's explanation makes 
sense to me, too).

                                     Randy.






^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Got warnings when overriding Initialize and Finalize
  2009-07-11  1:10   ` Randy Brukardt
@ 2009-07-14 14:54     ` Robert A Duff
  0 siblings, 0 replies; 5+ messages in thread
From: Robert A Duff @ 2009-07-14 14:54 UTC (permalink / raw)


"Randy Brukardt" <randy@rrsoftware.com> writes:

> "Adam Beneschan" <adam@irvine.com> wrote in message 
> news:16dc507c-4b96-4b53-b46f-2e806f988e6e@h18g2000yqj.googlegroups.com...
>>...But there isn't anything wrong with your
>> original code.
>
> For the record, I agree with Adam. Claw is full of overridings like this; 
> our rule was that overridings should be done in the private part as there is 
> no reason for the client to know whether the routines are overridden or just 
> inherited. Looks like a bogus warning to me (and Adam's explanation makes 
> sense to me, too).

For what it's worth, the latest version of GNAT Pro does not give
these bogus warnings.  I don't know if the fix has made it
into public version(s) yet.

- Bob



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-07-14 14:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-10 14:16 Got warnings when overriding Initialize and Finalize Hibou57 (Yannick Duchêne)
2009-07-10 15:34 ` Adam Beneschan
2009-07-10 16:12   ` Hibou57 (Yannick Duchêne)
2009-07-11  1:10   ` Randy Brukardt
2009-07-14 14:54     ` Robert A Duff

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