comp.lang.ada
 help / color / mirror / Atom feed
* Make specific warning error with gnat?
@ 2010-07-01 10:13 Markus Schoepflin
  2010-07-01 12:11 ` John B. Matthews
  2010-07-02  9:30 ` Stephen Leake
  0 siblings, 2 replies; 15+ messages in thread
From: Markus Schoepflin @ 2010-07-01 10:13 UTC (permalink / raw)


Hello,

I seem to remember that with gnat it was possible to turn a specific 
warning into an error. I couldn't find anything in the docs, now I'm not 
sure if this really was gnat or some other compiler which offered this feature.

Anyway, what I want is a compile time error for the warning 
"Constraint_Error" will be raised at run time.

Is this possible with gnat without turning all warnings into errors?

Regards,
Markus



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

* Re: Make specific warning error with gnat?
  2010-07-01 10:13 Make specific warning error with gnat? Markus Schoepflin
@ 2010-07-01 12:11 ` John B. Matthews
  2010-07-01 14:05   ` Markus Schoepflin
  2010-07-02  9:30 ` Stephen Leake
  1 sibling, 1 reply; 15+ messages in thread
From: John B. Matthews @ 2010-07-01 12:11 UTC (permalink / raw)


In article <i0hpoh$vmk$1@nntp.ilk.net>,
 Markus Schoepflin <nospam@no.spam> wrote:

> I seem to remember that with gnat it was possible to turn a specific 
> warning into an error. I couldn't find anything in the docs, now I'm not 
> sure if this really was gnat or some other compiler which offered this 
> feature.
> 
> Anyway, what I want is a compile time error for the warning 
> "Constraint_Error" will be raised at run time.
> 
> Is this possible with gnat without turning all warnings into errors?

You might be thinking of the -gnatwe option.

<http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gnat_ugn_unw/Warning-Message-Con
trol.html#Warning-Message-Control>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



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

* Re: Make specific warning error with gnat?
  2010-07-01 12:11 ` John B. Matthews
@ 2010-07-01 14:05   ` Markus Schoepflin
  2010-07-02  1:19     ` John B. Matthews
  0 siblings, 1 reply; 15+ messages in thread
From: Markus Schoepflin @ 2010-07-01 14:05 UTC (permalink / raw)


Am 01.07.2010 14:11, schrieb John B. Matthews:

> You might be thinking of the -gnatwe option.

No, as -gnatwe turns all warnings into errors. I want to turn a specific 
warning into an error, and leave the other warnings alone.

Markus



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

* Re: Make specific warning error with gnat?
  2010-07-01 14:05   ` Markus Schoepflin
@ 2010-07-02  1:19     ` John B. Matthews
  0 siblings, 0 replies; 15+ messages in thread
From: John B. Matthews @ 2010-07-02  1:19 UTC (permalink / raw)


In article <i0i7c7$nt2$1@nntp.ilk.net>,
 Markus Schoepflin <nospam@no.spam> wrote:

> Am 01.07.2010 14:11, schrieb John B. Matthews:
> 
> > You might be thinking of the -gnatwe option.
> 
> No, as -gnatwe turns all warnings into errors. I want to turn a specific 
> warning into an error, and leave the other warnings alone.

Ah, you want to turn a specific warning into an error, while not 
suppressing other warnings. I usually just condition the make options.

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



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

* Re: Make specific warning error with gnat?
  2010-07-01 10:13 Make specific warning error with gnat? Markus Schoepflin
  2010-07-01 12:11 ` John B. Matthews
@ 2010-07-02  9:30 ` Stephen Leake
  2010-07-02  9:44   ` Markus Schoepflin
  1 sibling, 1 reply; 15+ messages in thread
From: Stephen Leake @ 2010-07-02  9:30 UTC (permalink / raw)


Markus Schoepflin <nospam@no.spam> writes:

> Hello,
>
> I seem to remember that with gnat it was possible to turn a specific
> warning into an error. I couldn't find anything in the docs, now I'm
> not sure if this really was gnat or some other compiler which offered
> this feature.
>
> Anyway, what I want is a compile time error for the warning
> "Constraint_Error" will be raised at run time.
>
> Is this possible with gnat without turning all warnings into errors?

Just out of curiosity, why not treat all warnings as errors?

gnat is a very good compiler; the warnings it produces should be taken
seriously.

I have a policy of always eliminating all warnings. Sometimes that means
redesigning the code, which in the end turns out to be a good thing.

There are times when the only way to eliminate a warning is to use
pragma Warings (Off), or give a file-specific compiler option in a
project file. But that is rare, and the benefits from otherwise
eliminating warnings is large.

-- 
-- Stephe



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

* Re: Make specific warning error with gnat?
  2010-07-02  9:30 ` Stephen Leake
@ 2010-07-02  9:44   ` Markus Schoepflin
  2010-07-02 20:17     ` Randy Brukardt
                       ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Markus Schoepflin @ 2010-07-02  9:44 UTC (permalink / raw)


Am 02.07.2010 11:30, schrieb Stephen Leake:

> Markus Schoepflin<nospam@no.spam>  writes:

[...]

>> Is this possible with gnat without turning all warnings into errors?
>
> Just out of curiosity, why not treat all warnings as errors?
>
> gnat is a very good compiler; the warnings it produces should be taken
> seriously.

I would love to, but I'm dealing with a multi-million LOC legacy code base 
of Ada 83 in maintenance mode, which produces quite a large number of warnings.

I neither have the time nor the resources available to fix all of them, nor 
am I allowed to do so. But if the compiler already knows that there will be 
a constraint error at runtime, I would have liked the compilation to fail.

> I have a policy of always eliminating all warnings. Sometimes that means
> redesigning the code, which in the end turns out to be a good thing.
>
> There are times when the only way to eliminate a warning is to use
> pragma Warings (Off), or give a file-specific compiler option in a
> project file. But that is rare, and the benefits from otherwise
> eliminating warnings is large.

Markus



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

* Re: Make specific warning error with gnat?
  2010-07-02  9:44   ` Markus Schoepflin
@ 2010-07-02 20:17     ` Randy Brukardt
  2010-07-06 21:18       ` Robert A Duff
  2010-07-02 20:33     ` Georg Bauhaus
                       ` (2 subsequent siblings)
  3 siblings, 1 reply; 15+ messages in thread
From: Randy Brukardt @ 2010-07-02 20:17 UTC (permalink / raw)


"Markus Schoepflin" <nospam@no.spam> wrote in message 
news:i0kcdn$g44$1@nntp.ilk.net...
...
> I neither have the time nor the resources available to fix all of them, 
> nor am I allowed to do so. But if the compiler already knows that there 
> will be a constraint error at runtime, I would have liked the compilation 
> to fail.

Keep in mind that such a message may occur in cases where there is no actual 
problem. That can often happen if you have code that is conditional on 
constants. To take an extreme example, if you have:

      Max_Items := constant := 0;

and then the code is:

     if Max_Items /= 0 then
          Average := Float(Count)/Float(Max_Items); -- (1)
     else
          Average := 0.0;
     end if;

The code at (1) would raise Constraint_Error if it was executed, but of 
course it can never be executed. If you change the warning to an error here, 
you won't be able to compile the code without removing or changing the 
expression at (1), and that would cause problems if/when Max_Items is set to 
a different value.

                               Randy.






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

* Re: Make specific warning error with gnat?
  2010-07-02  9:44   ` Markus Schoepflin
  2010-07-02 20:17     ` Randy Brukardt
@ 2010-07-02 20:33     ` Georg Bauhaus
  2010-07-03 10:00       ` Dmitry A. Kazakov
  2010-07-05  8:16       ` Markus Schoepflin
  2010-07-03  8:01     ` Stephen Leake
  2010-07-06 21:12     ` Robert A Duff
  3 siblings, 2 replies; 15+ messages in thread
From: Georg Bauhaus @ 2010-07-02 20:33 UTC (permalink / raw)


On 7/2/10 11:44 AM, Markus Schoepflin wrote:

> I neither have the time nor the resources available to fix all of them,
> nor am I allowed to do so. But if the compiler already knows that there
> will be a constraint error at runtime, I would have liked the
> compilation to fail.

(I can't think of a way to do this without annotating each
occurrence in the source program: some programs might want
the constraint_error to be produced for whatever reason ...)
Anyway, grep has helped me scan traces of output and trigger
actions accordingly, that should be a workaround.
  I understand GPS is programmable, so maybe the log console
has hooks this sort of special case?




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

* Re: Make specific warning error with gnat?
  2010-07-02  9:44   ` Markus Schoepflin
  2010-07-02 20:17     ` Randy Brukardt
  2010-07-02 20:33     ` Georg Bauhaus
@ 2010-07-03  8:01     ` Stephen Leake
  2010-07-04  2:22       ` BrianG
  2010-07-06 21:12     ` Robert A Duff
  3 siblings, 1 reply; 15+ messages in thread
From: Stephen Leake @ 2010-07-03  8:01 UTC (permalink / raw)


Markus Schoepflin <nospam@no.spam> writes:

> Am 02.07.2010 11:30, schrieb Stephen Leake:
>
>> Markus Schoepflin<nospam@no.spam>  writes:
>
> [...]
>
>>> Is this possible with gnat without turning all warnings into errors?
>>
>> Just out of curiosity, why not treat all warnings as errors?
>>
>> gnat is a very good compiler; the warnings it produces should be taken
>> seriously.
>
> I would love to, but I'm dealing with a multi-million LOC legacy code
> base of Ada 83 in maintenance mode, which produces quite a large
> number of warnings.
>
> I neither have the time nor the resources available to fix all of
> them, nor am I allowed to do so. 

I can understand not changing design in a maintenance situation, but
adding 'pragma Warnings (off)' in places ought to be ok. Still, it can
be a lot of work.

> But if the compiler already knows that there will be a constraint
> error at runtime, I would have liked the compilation to fail.

Using GNAT project files, you can specify -gnatwe for particular files:

      for Switches ("sal-gen-alg.adb") use
        Standard_Common.Compiler'Default_Switches ("Ada") &
        Standard_Common.Compiler.Release_Switches & ("-gnatwe");

Not quite what you want, but it might help.

-- 
-- Stephe



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

* Re: Make specific warning error with gnat?
  2010-07-02 20:33     ` Georg Bauhaus
@ 2010-07-03 10:00       ` Dmitry A. Kazakov
  2010-07-05  8:16       ` Markus Schoepflin
  1 sibling, 0 replies; 15+ messages in thread
From: Dmitry A. Kazakov @ 2010-07-03 10:00 UTC (permalink / raw)


On Fri, 02 Jul 2010 22:33:25 +0200, Georg Bauhaus wrote:

> On 7/2/10 11:44 AM, Markus Schoepflin wrote:
> 
>> I neither have the time nor the resources available to fix all of them,
>> nor am I allowed to do so. But if the compiler already knows that there
>> will be a constraint error at runtime, I would have liked the
>> compilation to fail.
> 
> (I can't think of a way to do this without annotating each
> occurrence in the source program: some programs might want
> the constraint_error to be produced for whatever reason ...)

Yep, it is called contracted exceptions! BTW.

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



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

* Re: Make specific warning error with gnat?
  2010-07-03  8:01     ` Stephen Leake
@ 2010-07-04  2:22       ` BrianG
  0 siblings, 0 replies; 15+ messages in thread
From: BrianG @ 2010-07-04  2:22 UTC (permalink / raw)


Stephen Leake wrote:
> Markus Schoepflin <nospam@no.spam> writes:
>> Am 02.07.2010 11:30, schrieb Stephen Leake:
>>> Markus Schoepflin<nospam@no.spam>  writes:
>>> gnat is a very good compiler; the warnings it produces should be taken
>>> seriously.
>> I would love to, but I'm dealing with a multi-million LOC legacy code
>> base of Ada 83 in maintenance mode, which produces quite a large
>> number of warnings.
>>
>> I neither have the time nor the resources available to fix all of
>> them, nor am I allowed to do so. 
> 
> I can understand not changing design in a maintenance situation, but
> adding 'pragma Warnings (off)' in places ought to be ok. Still, it can
> be a lot of work.
> 
In many maintenance situations, _ANY_ source code change is an issue. 
The more files you change (in some situations the more lines you 
change), the greater the impact - on testing and on cost.  Adding 
pragmas throughout the code may be as large an impact as a 
moderate-to-large redesign.

Another GNAT warning I'd put in the same category is 'object XYZ is read 
but never written' (or something similar).  I saw this recently for a 
record type (defined in a different location), where all components have 
default value ... except for one which was added recently.



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

* Re: Make specific warning error with gnat?
  2010-07-02 20:33     ` Georg Bauhaus
  2010-07-03 10:00       ` Dmitry A. Kazakov
@ 2010-07-05  8:16       ` Markus Schoepflin
  1 sibling, 0 replies; 15+ messages in thread
From: Markus Schoepflin @ 2010-07-05  8:16 UTC (permalink / raw)


Am 02.07.2010 22:33, schrieb Georg Bauhaus:
> On 7/2/10 11:44 AM, Markus Schoepflin wrote:
>
>> I neither have the time nor the resources available to fix all of them,
>> nor am I allowed to do so. But if the compiler already knows that there
>> will be a constraint error at runtime, I would have liked the
>> compilation to fail.
>
> (I can't think of a way to do this without annotating each
> occurrence in the source program: some programs might want
> the constraint_error to be produced for whatever reason ...)

I'm sure some programs may want to raise constraint errors in their normal 
course of action, but I'm also sure it's always an error if one of the 
programs I'm dealing with statically raises a constraint error.

By the way, I found the compiler I had in mind in the first place. It was 
DEC's/Compaq's/HP's cxx compiler for Tru64. It had very elaborate features 
for message control. Each type of message had a unique tag and number, and 
you could redefine the severity of most messages by using the option 
-msg_<severity> <tag>, where severity is one of inform, warn, error, 
enable, disable.

So if constraint error would have had the tag CONSER for example, I could 
have said -msg_error CONSER, et voil�, mission accomplished.

> Anyway, grep has helped me scan traces of output and trigger
> actions accordingly, that should be a workaround.
> I understand GPS is programmable, so maybe the log console
> has hooks this sort of special case?

Yes, I think a grep output filter will be the way to go in my case.

Markus



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

* Re: Make specific warning error with gnat?
  2010-07-02  9:44   ` Markus Schoepflin
                       ` (2 preceding siblings ...)
  2010-07-03  8:01     ` Stephen Leake
@ 2010-07-06 21:12     ` Robert A Duff
  3 siblings, 0 replies; 15+ messages in thread
From: Robert A Duff @ 2010-07-06 21:12 UTC (permalink / raw)


Markus Schoepflin <nospam@no.spam> writes:

> I would love to, but I'm dealing with a multi-million LOC legacy code
> base of Ada 83 in maintenance mode, which produces quite a large number
> of warnings.

In that case, I think you should read the docs about the various
warning switches, and turn off the ones you wish to ignore,
and turn on the ones you wish to fix.  Then use -gnatwe to
make all warnings (the ones you turned on) into errors.
Then fix those: for each warning, if the code is wrong,
fix the bug, and if not, use pragma Warnings(Off).

Don't be shy about using Warnings(Off).  The compiler is
sometimes wrong to warn, and the Warnings(Off) (with
a suitable comment) documents the fact that something
fishy is going on, but in this particular case it's OK.
Don't contort the code just to make the compiler happy.
It's usually a good idea to use the form of the pragma
that gives the warning text.

Note that you can turn off warnings globally in two ways:
with switches, or with pragmas in a configuration file.
The latter can be as fine-grained as you like.

For new code, -gnatwae is a good idea.  But that's
not your case.

- Bob



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

* Re: Make specific warning error with gnat?
  2010-07-02 20:17     ` Randy Brukardt
@ 2010-07-06 21:18       ` Robert A Duff
  2010-07-07 23:32         ` Randy Brukardt
  0 siblings, 1 reply; 15+ messages in thread
From: Robert A Duff @ 2010-07-06 21:18 UTC (permalink / raw)


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

> Keep in mind that such a message may occur in cases where there is no actual 
> problem.

Right.

>...That can often happen if you have code that is conditional on 
> constants. To take an extreme example, if you have:
>
>       Max_Items := constant := 0;
>
> and then the code is:
>
>      if Max_Items /= 0 then
>           Average := Float(Count)/Float(Max_Items); -- (1)
>      else
>           Average := 0.0;
>      end if;
>
> The code at (1) would raise Constraint_Error if it was executed, but of 
> course it can never be executed. If you change the warning to an error here, 
> you won't be able to compile the code without removing or changing the 
> expression at (1), and that would cause problems if/when Max_Items is set to 
> a different value.

You don't actually need to change (1).  This is what pragma
Warnings(Off) is for.  I don't know if GNAT warns about the
above (I think it might notice that (1) is dead code), but if
it does, tell it to shut up (after carefully making sure the
warning is indeed bogus).

In a case like this, Max_Items is probably declared in some package that
has multiple variants, which are selected by build options (e.g. GNAT
project files).  Of course you need to test all the variants.

You can put Warnings(off/on) around just the one line of code.

- Bob



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

* Re: Make specific warning error with gnat?
  2010-07-06 21:18       ` Robert A Duff
@ 2010-07-07 23:32         ` Randy Brukardt
  0 siblings, 0 replies; 15+ messages in thread
From: Randy Brukardt @ 2010-07-07 23:32 UTC (permalink / raw)


"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message 
news:wcctyocqph3.fsf@shell01.TheWorld.com...
> "Randy Brukardt" <randy@rrsoftware.com> writes:
>
>> Keep in mind that such a message may occur in cases where there is no 
>> actual
>> problem.
>
> Right.
>
>>...That can often happen if you have code that is conditional on
>> constants. To take an extreme example, if you have:
>>
>>       Max_Items := constant := 0;
>>
>> and then the code is:
>>
>>      if Max_Items /= 0 then
>>           Average := Float(Count)/Float(Max_Items); -- (1)
>>      else
>>           Average := 0.0;
>>      end if;
>>
>> The code at (1) would raise Constraint_Error if it was executed, but of
>> course it can never be executed. If you change the warning to an error 
>> here,
>> you won't be able to compile the code without removing or changing the
>> expression at (1), and that would cause problems if/when Max_Items is set 
>> to
>> a different value.
>
> You don't actually need to change (1).  This is what pragma
> Warnings(Off) is for.  I don't know if GNAT warns about the
> above (I think it might notice that (1) is dead code), but if
> it does, tell it to shut up (after carefully making sure the
> warning is indeed bogus).

Right. I don't know the details about GNAT, it might be harder to create 
such an example than it would be for Janus/Ada (which makes these warning 
checks during static expression evaluation, which is early during 
compilation, while dead code elimination is much later). In general, 
compilers may do the various tasks in different orders, and thus get 
different warnings. (That one of many reasons why it is good to try code 
that is intended to be portable on multiple compilers).

                            Randy.


> In a case like this, Max_Items is probably declared in some package that
> has multiple variants, which are selected by build options (e.g. GNAT
> project files).  Of course you need to test all the variants.
>
> You can put Warnings(off/on) around just the one line of code.
>
> - Bob 





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

end of thread, other threads:[~2010-07-07 23:32 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-01 10:13 Make specific warning error with gnat? Markus Schoepflin
2010-07-01 12:11 ` John B. Matthews
2010-07-01 14:05   ` Markus Schoepflin
2010-07-02  1:19     ` John B. Matthews
2010-07-02  9:30 ` Stephen Leake
2010-07-02  9:44   ` Markus Schoepflin
2010-07-02 20:17     ` Randy Brukardt
2010-07-06 21:18       ` Robert A Duff
2010-07-07 23:32         ` Randy Brukardt
2010-07-02 20:33     ` Georg Bauhaus
2010-07-03 10:00       ` Dmitry A. Kazakov
2010-07-05  8:16       ` Markus Schoepflin
2010-07-03  8:01     ` Stephen Leake
2010-07-04  2:22       ` BrianG
2010-07-06 21:12     ` 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