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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Strange warning message Date: Mon, 27 Nov 2017 11:42:09 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <7c246c12-77f6-45c9-a05a-9afe934df332@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 27 Nov 2017 10:42:10 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="25d5666bb66c2b08db19bd32f89bb645"; logging-data="13252"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+PlW9E5Q7xUdAeUlErEbWxt02yLeuBhtc=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 In-Reply-To: <7c246c12-77f6-45c9-a05a-9afe934df332@googlegroups.com> Content-Language: en-US Cancel-Lock: sha1:YFs7M9gZ/GvHxr4KQAoQwtax8RQ= Xref: reader02.eternal-september.org comp.lang.ada:49182 Date: 2017-11-27T11:42:09+01:00 List-Id: On 11/27/2017 09:40 AM, reinert wrote: > > when I compile the enclosed program with option "-gnatwa" (i.e. "gnatmake -gnatwa test1k.adb", I get the following annoying warning: > > "warning: useless assignment to "test1", value never referenced" In order to produce warnings like this, the compiler has to do some data-flow analysis. The amount of data-flow analysis required by the ARM is zero. So GNAT is making an extra effort to be helpful. That the warning is annoying in this case is the price you pay for it being correct in most others. Clearly GNAT's data-flow analysis is incomplete, or it would also flag the assignment in the loop. Complete data-flow analysis is possible (SPARK does it). but apparently it's hard, and possibly not really compatible with a compiler's main purpose, but even if GNAT did have complete data-flow analysis, you'd still get the warning. I found that even if I change the loop to for I in Test1'range loop Test1 (I) := new Test1_T; end loop; GNAT (7.2) still doesn't flag the assignment in the loop, so it's not just that GNAT's analysis hasn't caught up with the new "for E of" construct. -- Jeff Carter "We burst our pimples at you." Monty Python & the Holy Grail 16