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,50856407da0f240e X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.193.129 with SMTP id ho1mr707381pbc.8.1340308831724; Thu, 21 Jun 2012 13:00:31 -0700 (PDT) MIME-Version: 1.0 Path: l9ni4327pbj.0!nntp.google.com!news2.google.com!goblin3!goblin.stu.neva.ru!gegeweb.org!news.ecp.fr!news.jacob-sparre.dk!munin.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: why this construct causes aliasing problem in 2012 with functions allowing In Out? Date: Thu, 21 Jun 2012 15:00:25 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <2adb0da6-9b6e-4514-b703-f0a6261ecc5b@googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1340308830 11543 69.95.181.76 (21 Jun 2012 20:00:30 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Thu, 21 Jun 2012 20:00:30 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-RFC2646: Format=Flowed; Original Date: 2012-06-21T15:00:25-05:00 List-Id: "Adam Beneschan" wrote in message news:2adb0da6-9b6e-4514-b703-f0a6261ecc5b@googlegroups.com... > On Wednesday, June 20, 2012 1:24:11 AM UTC-7, Nasser M. Abbasi wrote: >> looking at http://www.slideshare.net/AdaCore/ada-2012 >> >> (typing it myself looking at the screen) >> >> -------------------------- >> function change(x,y : in out integer) return integer is >> begin >> x := x*2; >> y := y*4; >> return x+y; >> end >> >> one , two : integer :=1; >> begin >> two := change(one,two)+ change(one,two); --> >> end >> ----------------------------- >> >> They say it will generate >> >> warning: result may differ if evaluated after actual in expression. Apparently, they haven't implemented the aliasing checks completely yet, because this program is clearly illegal in Ada 2012. It violates 6.4.1(6.17-18/3): If a construct C has two or more direct constituents that are names or expressions whose evaluation may occur in an arbitrary order, at least one of which contains a function call with an in out or out parameter, then the construct is legal only if: For each name N that is passed as a parameter of mode in out or out to some inner function call C2 (not including the construct C itself), there is no other name anywhere within a direct constituent of the construct C other than the one containing C2, that is known to refer to the same object. If you consider the call to "+" to be C, then the uses of "One" and "Two" in one of the calls to Change are "known to refer to the same object" as the uses of "One" and "Two" in the other call to Change. Thus the call to "+" is illegal (not just a warning). (I'm not sure if the response is accurately portrayed, so I'm not quite willing to call this a bug.) Randy.