comp.lang.ada
 help / color / mirror / Atom feed
* Warnings about hiding
@ 2010-10-08 12:47 Julian Leyh
  2010-10-08 19:46 ` Adam Beneschan
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Julian Leyh @ 2010-10-08 12:47 UTC (permalink / raw)


Hi,

"-gnatwh" activates warnings on hiding declarations. But sometimes,
hiding is necessary.

For example, consider this (Controlled type with it's own comparison
operator and finalize procedure, you can reproduce the errors using
these ads files):

$ cat foo.ads
with Ada.Finalization;
package foo is
   type Foobar is new Ada.Finalization.Controlled with null record;
   function "=" (L,R : in Foobar) return Boolean;
private
   procedure Finalize (Object : in out Foobar);
end foo;
$ gnat -gnatwh -gnatc foo.ads
gcc -c -gnatwh -gnatc foo.ads
foo.ads:4:13: warning: declaration of "=" hides one in package
Standard
foo.ads:6:14: warning: declaration of "Finalize" hides one at line 3
$

The only way i see to solve this, is using pragma Warnings (Off); like
this:

$ cat bar.ads
with Ada.Finalization;
package bar is
   type Barfoo is new Ada.Finalization.Controlled with null record;
pragma Warnings(Off);
   function "=" (L,R : in Barfoo) return Boolean;
pragma Warnings(On);
private
   procedure Finalize (Object : in out Barfoo);
end bar;
$ gnatmake -gnatc -gnatwh bar.ads
gcc -c -gnatwh -gnatc bar.ads
bar.ads:8:14: warning: declaration of "Finalize" hides one at line 3
$

But that would either remove all warnings between both pragmas, or I
would have to put them around every occurence of the hiding. I don't
like turning all warnings off at once and I don't like adding two
lines of source code just to prevent the warning. Still, I would like
to remove them (without removing -gnatwh).

Is there a proper way to do this?

Greetings,
Julian



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

* Re: Warnings about hiding
  2010-10-08 12:47 Warnings about hiding Julian Leyh
@ 2010-10-08 19:46 ` Adam Beneschan
  2010-10-08 20:24   ` Simon Wright
  2010-10-09  1:31 ` Vinzent Hoefler
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Adam Beneschan @ 2010-10-08 19:46 UTC (permalink / raw)


On Oct 8, 5:47 am, Julian Leyh <jul...@vgai.de> wrote:
> Hi,
>
> "-gnatwh" activates warnings on hiding declarations. But sometimes,
> hiding is necessary.
>
> For example, consider this (Controlled type with it's own comparison
> operator and finalize procedure, you can reproduce the errors using
> these ads files):
>
> $ cat foo.ads
> with Ada.Finalization;
> package foo is
>    type Foobar is new Ada.Finalization.Controlled with null record;
>    function "=" (L,R : in Foobar) return Boolean;
> private
>    procedure Finalize (Object : in out Foobar);
> end foo;
> $ gnat -gnatwh -gnatc foo.ads
> gcc -c -gnatwh -gnatc foo.ads
> foo.ads:4:13: warning: declaration of "=" hides one in package
> Standard
> foo.ads:6:14: warning: declaration of "Finalize" hides one at line 3
> $

Well, I was going to suggest using the "overriding" keyword (not a bad
idea anyway), but when I tried it, GNAT still displayed the warnings.
Now *that* looks like a bug.  (I'm using 4.3.3; maybe it's been fixed
in a later version)

                              -- Adam



> The only way i see to solve this, is using pragma Warnings (Off); like
> this:
>
> $ cat bar.ads
> with Ada.Finalization;
> package bar is
>    type Barfoo is new Ada.Finalization.Controlled with null record;
> pragma Warnings(Off);
>    function "=" (L,R : in Barfoo) return Boolean;
> pragma Warnings(On);
> private
>    procedure Finalize (Object : in out Barfoo);
> end bar;
> $ gnatmake -gnatc -gnatwh bar.ads
> gcc -c -gnatwh -gnatc bar.ads
> bar.ads:8:14: warning: declaration of "Finalize" hides one at line 3
> $
>
> But that would either remove all warnings between both pragmas, or I
> would have to put them around every occurence of the hiding. I don't
> like turning all warnings off at once and I don't like adding two
> lines of source code just to prevent the warning. Still, I would like
> to remove them (without removing -gnatwh).
>
> Is there a proper way to do this?
>
> Greetings,
> Julian




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

* Re: Warnings about hiding
  2010-10-08 19:46 ` Adam Beneschan
@ 2010-10-08 20:24   ` Simon Wright
  0 siblings, 0 replies; 13+ messages in thread
From: Simon Wright @ 2010-10-08 20:24 UTC (permalink / raw)


Adam Beneschan <adam@irvine.com> writes:

> On Oct 8, 5:47 am, Julian Leyh <jul...@vgai.de> wrote:
>> Hi,
>>
>> "-gnatwh" activates warnings on hiding declarations. But sometimes,
>> hiding is necessary.
>>
>> For example, consider this (Controlled type with it's own comparison
>> operator and finalize procedure, you can reproduce the errors using
>> these ads files):
>>
>> $ cat foo.ads
>> with Ada.Finalization;
>> package foo is
>>    type Foobar is new Ada.Finalization.Controlled with null record;
>>    function "=" (L,R : in Foobar) return Boolean;
>> private
>>    procedure Finalize (Object : in out Foobar);
>> end foo;
>> $ gnat -gnatwh -gnatc foo.ads
>> gcc -c -gnatwh -gnatc foo.ads
>> foo.ads:4:13: warning: declaration of "=" hides one in package
>> Standard
>> foo.ads:6:14: warning: declaration of "Finalize" hides one at line 3
>> $
>
> Well, I was going to suggest using the "overriding" keyword (not a bad
> idea anyway), but when I tried it, GNAT still displayed the warnings.
> Now *that* looks like a bug.  (I'm using 4.3.3; maybe it's been fixed
> in a later version)

Still there in GCC 4.5.0 & GNAT GPL 2010.



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

* Re: Warnings about hiding
  2010-10-08 12:47 Warnings about hiding Julian Leyh
  2010-10-08 19:46 ` Adam Beneschan
@ 2010-10-09  1:31 ` Vinzent Hoefler
  2010-10-09  6:51   ` Randy Brukardt
  2010-10-09 11:18 ` anon
  2010-10-26  1:16 ` Yannick Duchêne (Hibou57)
  3 siblings, 1 reply; 13+ messages in thread
From: Vinzent Hoefler @ 2010-10-09  1:31 UTC (permalink / raw)


On Fri, 08 Oct 2010 14:47:05 +0200, Julian Leyh <julian@vgai.de> wrote:

> $ cat foo.ads
> with Ada.Finalization;
> package foo is
>    type Foobar is new Ada.Finalization.Controlled with null record;
>    function "=" (L,R : in Foobar) return Boolean;
> private
>    procedure Finalize (Object : in out Foobar);
> end foo;
> $ gnat -gnatwh -gnatc foo.ads
> gcc -c -gnatwh -gnatc foo.ads
> foo.ads:4:13: warning: declaration of "=" hides one in package
> Standard
> foo.ads:6:14: warning: declaration of "Finalize" hides one at line 3
> $

JFTR: If you move "Finalize" into the public part, the warning for it
disappears (just tested with GNAT GPL 2010).

(IMO, there's no point putting it in the private part, the operation
is already known, anyway.)


Vinzent.

-- 
There is no signature.



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

* Re: Warnings about hiding
  2010-10-09  1:31 ` Vinzent Hoefler
@ 2010-10-09  6:51   ` Randy Brukardt
  2010-10-09  8:08     ` Dmitry A. Kazakov
  2010-10-26  1:28     ` Yannick Duchêne (Hibou57)
  0 siblings, 2 replies; 13+ messages in thread
From: Randy Brukardt @ 2010-10-09  6:51 UTC (permalink / raw)


"Vinzent Hoefler" <nntp-2010-10@t-domaingrabbing.de> wrote in message 
news:op.vkabvkw30k3wt7@jellix.jlfencey.com...
...
> JFTR: If you move "Finalize" into the public part, the warning for it
> disappears (just tested with GNAT GPL 2010).
>
> (IMO, there's no point putting it in the private part, the operation
> is already known, anyway.)

My opinion is exactly the reverse: there is no point in putting it in the 
visible part in this case -- it should not matter to clients whether or not 
the subprogram is overridden, so why burden them with it??

That assumes of course that the clients are smart enough (or have good 
tools) which can show them what is actually inherited. In the absense of 
that, you really have to override everything in the public part, whether you 
want to or not, else no one will know that the operations even exist - no 
one can figure out by hand what's inherited. (I vote for good tools. :-)

                                        Randy.





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

* Re: Warnings about hiding
  2010-10-09  6:51   ` Randy Brukardt
@ 2010-10-09  8:08     ` Dmitry A. Kazakov
  2010-10-26  1:34       ` Yannick Duchêne (Hibou57)
  2010-10-26  1:28     ` Yannick Duchêne (Hibou57)
  1 sibling, 1 reply; 13+ messages in thread
From: Dmitry A. Kazakov @ 2010-10-09  8:08 UTC (permalink / raw)


On Sat, 9 Oct 2010 01:51:47 -0500, Randy Brukardt wrote:

> "Vinzent Hoefler" <nntp-2010-10@t-domaingrabbing.de> wrote in message 
> news:op.vkabvkw30k3wt7@jellix.jlfencey.com...
> ...
>> JFTR: If you move "Finalize" into the public part, the warning for it
>> disappears (just tested with GNAT GPL 2010).
>>
>> (IMO, there's no point putting it in the private part, the operation
>> is already known, anyway.)
> 
> My opinion is exactly the reverse: there is no point in putting it in the 
> visible part in this case -- it should not matter to clients whether or not 
> the subprogram is overridden, so why burden them with it??

It does matter:

1. Clients dealing with specific types shall be able to call manifested
operations of the type.

2. Clients which publicly derive from a parent type must call the parent's
Finalize from their implementations of Finalize.

> That assumes of course that the clients are smart enough (or have good 
> tools) which can show them what is actually inherited. In the absense of 
> that, you really have to override everything in the public part, whether you 
> want to or not, else no one will know that the operations even exist - no 
> one can figure out by hand what's inherited. (I vote for good tools. :-)

I vote for language fixes:

1. Finalize in the role of a destructor shall not be callable at all

2. When overridden the parent's implementation of Finalize shall be called
automatically.

3. Private overriding of a public interface shall be illegal. I.e. if Foo
is a public operation of T then either so:

   type S is new T with private;
   overriding procedure Foo (X : T);

or else so:

   type S is private;
private
   type S is new T with ...;
   overriding procedure Foo (X : T);

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Warnings about hiding
  2010-10-08 12:47 Warnings about hiding Julian Leyh
  2010-10-08 19:46 ` Adam Beneschan
  2010-10-09  1:31 ` Vinzent Hoefler
@ 2010-10-09 11:18 ` anon
  2010-10-09 19:11   ` Simon Wright
  2010-10-26  1:16 ` Yannick Duchêne (Hibou57)
  3 siblings, 1 reply; 13+ messages in thread
From: anon @ 2010-10-09 11:18 UTC (permalink / raw)


In <44e7dff1-04f5-46ad-8521-e4fe030c9c29@26g2000yqv.googlegroups.com>, Julian Leyh <julian@vgai.de> writes:
>Hi,
>
>"-gnatwh" activates warnings on hiding declarations. But sometimes,
>hiding is necessary.
>
>For example, consider this (Controlled type with it's own comparison
>operator and finalize procedure, you can reproduce the errors using
>these ads files):
>
>$ cat foo.ads
>with Ada.Finalization;
>package foo is
>   type Foobar is new Ada.Finalization.Controlled with null record;
>   function "=" (L,R : in Foobar) return Boolean;
>private
>   procedure Finalize (Object : in out Foobar);
>end foo;
>$ gnat -gnatwh -gnatc foo.ads
>gcc -c -gnatwh -gnatc foo.ads
>foo.ads:4:13: warning: declaration of "=" hides one in package
>Standard
>foo.ads:6:14: warning: declaration of "Finalize" hides one at line 3
>$
>
>The only way i see to solve this, is using pragma Warnings (Off); like
>this:
>
>$ cat bar.ads
>with Ada.Finalization;
>package bar is
>   type Barfoo is new Ada.Finalization.Controlled with null record;
>pragma Warnings(Off);
>   function "=" (L,R : in Barfoo) return Boolean;
>pragma Warnings(On);
>private
>   procedure Finalize (Object : in out Barfoo);
>end bar;
>$ gnatmake -gnatc -gnatwh bar.ads
>gcc -c -gnatwh -gnatc bar.ads
>bar.ads:8:14: warning: declaration of "Finalize" hides one at line 3
>$
>
>But that would either remove all warnings between both pragmas, or I
>would have to put them around every occurence of the hiding. I don't
>like turning all warnings off at once and I don't like adding two
>lines of source code just to prevent the warning. Still, I would like
>to remove them (without removing -gnatwh).
>
>Is there a proper way to do this?
>
>Greetings,
>Julian

RM 8.3 (19) defines your problem.  In your example there is no fix.  Your 
just trying to violate Ada's visibility rules is all.

Plus, the "-gnatwh" just states which routines or variables that are hidden by 
redefinition or overloading routines and variables.

So, drop the requirement of using "-gnatwh" is the only answer.  Unless you 
want or need to see what caused the first routine or variable to be hidden.


To see a better example of this. Copy s-fileio.ad? (System.File_io.ad?) to a 
test directory and compile using "-gnatwh".  I chose s-fileio.ad? because it 
has and similar code as your example.  In compiling you will get all kinds 
of warning messages about like 
  "declaration hides "SSL" at a-except.ads"
or 
  "declaration of "Finalize" hides one at line"





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

* Re: Warnings about hiding
  2010-10-09 11:18 ` anon
@ 2010-10-09 19:11   ` Simon Wright
  2010-10-09 20:11     ` anon
  0 siblings, 1 reply; 13+ messages in thread
From: Simon Wright @ 2010-10-09 19:11 UTC (permalink / raw)


anon@anon.org writes:

> So, drop the requirement of using "-gnatwh" is the only answer.
> Unless you want or need to see what caused the first routine or
> variable to be hidden.

In similar vein I use -gnatwaL because I don't want to know about all
the elaboration-order checks one might need if not using GNAT's static
elaboration.

On the other hand, I really would have thought that an overriding
subprogram shouldn't provoke the warning...



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

* Re: Warnings about hiding
  2010-10-09 19:11   ` Simon Wright
@ 2010-10-09 20:11     ` anon
  0 siblings, 0 replies; 13+ messages in thread
From: anon @ 2010-10-09 20:11 UTC (permalink / raw)


In <m2y6a7i3k9.fsf@pushface.org>, Simon Wright <simon@pushface.org> writes:
>anon@anon.org writes:
>
>> So, drop the requirement of using "-gnatwh" is the only answer.
>> Unless you want or need to see what caused the first routine or
>> variable to be hidden.
>
>In similar vein I use -gnatwaL because I don't want to know about all
>the elaboration-order checks one might need if not using GNAT's static
>elaboration.
>
>On the other hand, I really would have thought that an overriding
>subprogram shouldn't provoke the warning...

You could say its a built-in debugging/learning tools, just like the spell 
checker that GNAT contains. Adacore has spent a great deal of time to help 
programmers understand were errors can and do occur using the source code. 
Just like they did by aiding programmers with syntax errors by including the 
spell checker with the best guess on the misspelled word.





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

* Re: Warnings about hiding
  2010-10-08 12:47 Warnings about hiding Julian Leyh
                   ` (2 preceding siblings ...)
  2010-10-09 11:18 ` anon
@ 2010-10-26  1:16 ` Yannick Duchêne (Hibou57)
  2010-10-26  9:32   ` J-P. Rosen
  3 siblings, 1 reply; 13+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2010-10-26  1:16 UTC (permalink / raw)


Le Fri, 08 Oct 2010 14:47:05 +0200, Julian Leyh <julian@vgai.de> a écrit:

> Hi,
>
> "-gnatwh" activates warnings on hiding declarations. But sometimes,
> hiding is necessary.
>
> For example, consider this (Controlled type with it's own comparison
> operator and finalize procedure, you can reproduce the errors using
> these ads files):
>
> $ cat foo.ads
> with Ada.Finalization;
> package foo is
>    type Foobar is new Ada.Finalization.Controlled with null record;
>    function "=" (L,R : in Foobar) return Boolean;
> private
>    procedure Finalize (Object : in out Foobar);
> end foo;
> $ gnat -gnatwh -gnatc foo.ads
> gcc -c -gnatwh -gnatc foo.ads
> foo.ads:4:13: warning: declaration of "=" hides one in package
> Standard
> foo.ads:6:14: warning: declaration of "Finalize" hides one at line 3
> $
>
> The only way i see to solve this, is using pragma Warnings (Off); like
> this:
>
> $ cat bar.ads
> with Ada.Finalization;
> package bar is
>    type Barfoo is new Ada.Finalization.Controlled with null record;
> pragma Warnings(Off);
>    function "=" (L,R : in Barfoo) return Boolean;
> pragma Warnings(On);
> private
>    procedure Finalize (Object : in out Barfoo);
> end bar;
> $ gnatmake -gnatc -gnatwh bar.ads
> gcc -c -gnatwh -gnatc bar.ads
> bar.ads:8:14: warning: declaration of "Finalize" hides one at line 3
> $
>
> But that would either remove all warnings between both pragmas, or I
> would have to put them around every occurence of the hiding. I don't
> like turning all warnings off at once and I don't like adding two
> lines of source code just to prevent the warning. Still, I would like
> to remove them (without removing -gnatwh).
>
> Is there a proper way to do this?
(warnings check may be rough, this is less trustable than a conformance to  
the language semantic)
Yes, there is a cleaner way to do this : use AdaControl, which allow finer  
level of control.
http://adalog.pagesperso-orange.fr/adacontrol2.htm
You may either make a request to Jean-Pierre Rosen for commercial support,  
that is, to add this particular test in AdaControl's capabilities or else  
use the source (which is provided) to add your own hook (the source is  
mostly well designed and readable).


-- 
Si les chats miaulent et font autant de vocalises bizarres, c’est pas pour  
les chiens.



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

* Re: Warnings about hiding
  2010-10-09  6:51   ` Randy Brukardt
  2010-10-09  8:08     ` Dmitry A. Kazakov
@ 2010-10-26  1:28     ` Yannick Duchêne (Hibou57)
  1 sibling, 0 replies; 13+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2010-10-26  1:28 UTC (permalink / raw)


Le Sat, 09 Oct 2010 08:51:47 +0200, Randy Brukardt <randy@rrsoftware.com>  
a écrit:
> That assumes of course that the clients are smart enough (or have good
> tools) which can show them what is actually inherited. In the absense of
> that, you really have to override everything in the public part, whether  
> you
> want to or not, else no one will know that the operations even exist - no
> one can figure out by hand what's inherited. (I vote for good tools. :-)
Unfortunately, this requirement is not part of any standard ;) May be this  
should…

    “Ada Tools Requirement Reference Manual v 2011” by Randy Brukardt

That is indeed an issue, the assumptions which can be made here.

-- 
Si les chats miaulent et font autant de vocalises bizarres, c’est pas pour  
les chiens.



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

* Re: Warnings about hiding
  2010-10-09  8:08     ` Dmitry A. Kazakov
@ 2010-10-26  1:34       ` Yannick Duchêne (Hibou57)
  0 siblings, 0 replies; 13+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2010-10-26  1:34 UTC (permalink / raw)


Le Sat, 09 Oct 2010 10:08:17 +0200, Dmitry A. Kazakov  
<mailbox@dmitry-kazakov.de> a écrit:
> I vote for language fixes:
>
> 1. Finalize in the role of a destructor shall not be callable at all
What about entity instances living in dynamic memory allocations ?

-- 
Si les chats miaulent et font autant de vocalises bizarres, c’est pas pour  
les chiens.



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

* Re: Warnings about hiding
  2010-10-26  1:16 ` Yannick Duchêne (Hibou57)
@ 2010-10-26  9:32   ` J-P. Rosen
  0 siblings, 0 replies; 13+ messages in thread
From: J-P. Rosen @ 2010-10-26  9:32 UTC (permalink / raw)


Le 26/10/2010 03:16, Yannick Duchêne (Hibou57) a écrit :
> Yes, there is a cleaner way to do this : use AdaControl, which allow
> finer level of control.
> http://adalog.pagesperso-orange.fr/adacontrol2.htm
> You may either make a request to Jean-Pierre Rosen for commercial
> support, that is, to add this particular test in AdaControl's
> capabilities or else use the source (which is provided) to add your own
> hook (the source is mostly well designed and readable).
> 
Thanks for the kind words, but please don't use the "pagesperso-orange"
in any reference, use http://www.adalog.fr/adacontrol2.htm

(Orange is my physical provider, they recently changed their name, which
sinked my previous attempts to hide the physical name. As a result,
Google references orange.fr instead of adalog.fr - I have a terrible
time to try to fix that, please don't add more references to it. I think
I'll have to change provider).

-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Adalog a déménagé / Adalog has moved:
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00



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

end of thread, other threads:[~2010-10-26  9:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-08 12:47 Warnings about hiding Julian Leyh
2010-10-08 19:46 ` Adam Beneschan
2010-10-08 20:24   ` Simon Wright
2010-10-09  1:31 ` Vinzent Hoefler
2010-10-09  6:51   ` Randy Brukardt
2010-10-09  8:08     ` Dmitry A. Kazakov
2010-10-26  1:34       ` Yannick Duchêne (Hibou57)
2010-10-26  1:28     ` Yannick Duchêne (Hibou57)
2010-10-09 11:18 ` anon
2010-10-09 19:11   ` Simon Wright
2010-10-09 20:11     ` anon
2010-10-26  1:16 ` Yannick Duchêne (Hibou57)
2010-10-26  9:32   ` J-P. Rosen

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