comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Make specific warning error with gnat?
Date: Wed, 7 Jul 2010 18:32:37 -0500
Date: 2010-07-07T18:32:37-05:00	[thread overview]
Message-ID: <i132qn$eun$1@munin.nbi.dk> (raw)
In-Reply-To: wcctyocqph3.fsf@shell01.TheWorld.com

"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 





  reply	other threads:[~2010-07-07 23:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
replies disabled

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