From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,71d79ed4fdc42ae2 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news.glorb.com!news.mv.net!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Make specific warning error with gnat? Date: Tue, 06 Jul 2010 17:18:00 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <82mxuaxmb1.fsf@stephe-leake.org> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1278451067 15216 192.74.137.71 (6 Jul 2010 21:17:47 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 6 Jul 2010 21:17:47 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:6EPkW2M4y/M+S/KxOqlnVym2WFU= Xref: g2news2.google.com comp.lang.ada:13209 Date: 2010-07-06T17:18:00-04:00 List-Id: "Randy Brukardt" 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