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: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!news.in2p3.fr!in2p3.fr!news.ecp.fr!news.jacob-sparre.dk!pnx.dk!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Make specific warning error with gnat? Date: Wed, 7 Jul 2010 18:32:37 -0500 Organization: Jacob Sparre Andersen Message-ID: References: <82mxuaxmb1.fsf@stephe-leake.org> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1278545559 15319 69.95.181.76 (7 Jul 2010 23:32:39 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Wed, 7 Jul 2010 23:32:39 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5843 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 Xref: g2news1.google.com comp.lang.ada:12258 Date: 2010-07-07T18:32:37-05:00 List-Id: "Robert A Duff" wrote in message news:wcctyocqph3.fsf@shell01.TheWorld.com... > "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). 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