comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: why this construct causes aliasing problem in 2012 with functions allowing In Out?
Date: Thu, 21 Jun 2012 15:00:25 -0500
Date: 2012-06-21T15:00:25-05:00	[thread overview]
Message-ID: <jrvugt$b8n$1@munin.nbi.dk> (raw)
In-Reply-To: 2adb0da6-9b6e-4514-b703-f0a6261ecc5b@googlegroups.com

"Adam Beneschan" <adam@irvine.com> 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.





      parent reply	other threads:[~2012-06-21 20:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-20  8:24 why this construct causes aliasing problem in 2012 with functions allowing In Out? Nasser M. Abbasi
2012-06-20  8:26 ` Nasser M. Abbasi
2012-06-20 14:56 ` Adam Beneschan
2012-06-20 15:14   ` Dmitry A. Kazakov
2012-06-21 20:06     ` Randy Brukardt
2012-06-21 20:00   ` Randy Brukardt [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox