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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder.news-service.com!newsfeed101.telia.com!nf02.dk.telia.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Sun, 06 Sep 2009 22:09:06 +0200 From: Georg Bauhaus Reply-To: rm.tsoh+bauhaus@maps.futureapps.de User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: renaming function result object inside loop References: <4aa2a2ed$0$32665$9b4e6d93@newsspool2.arcor-online.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4aa416e3$0$30234$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 06 Sep 2009 22:09:07 CEST NNTP-Posting-Host: 8eb47464.newsspool1.arcor-online.net X-Trace: DXC=IZYKbff4oFhOKO]LCQ@0g`ic==]BZ:afn4Fo<]lROoRa^YC2XCjHcbio[>BT\anaEh X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:8198 Date: 2009-09-06T22:09:07+02:00 List-Id: Robert A Duff wrote: > Georg Bauhaus writes: > >> Is the following a spurious warning? >> >> 528. loop >> 529. declare >> 530. Line : String renames LIO.Get_Line; --! >> | >> >>> warning: renaming function result object is suspicious >> >>> warning: function "Get_Line" will be called only once >> >>> warning: suggest using an initialized constant object instead >> >> (Get_Line in fact seems to be called each time around the loop.) > [...] > In the first case, Get_Line is called "once" (i.e. when the > declaration of Line is elaborated), whereas in the second case, > Get_Line is called every time you say "Line". > > Since a constant: > > Line : constant String := LIO.Get_Line; > > has the same semantics as the first renaming, > it seems preferable (and if you're lucky, the > compiler will generate the same code). Thanks for the clarification. I was in FUD whether Ada 2005 had changed things in agreement with the warning. Which I clearly have misunderstood. A thought about both confusing issues with renaming result objects then: If 'Result makes it into the language, is renaming a function result an opportunity to allow 'Result? Line : String renames LIO.Get_Line'Result; Anyway, http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41286