comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Is this a bug in my code or the compiler?
Date: Sat, 13 Jun 2015 22:10:34 -0500
Date: 2015-06-13T22:10:34-05:00	[thread overview]
Message-ID: <mlirbb$ni2$1@loke.gir.dk> (raw)
In-Reply-To: 4f4cd4b1-0a6d-441b-a4f7-98add70e4e1e@googlegroups.com

"David Botton" <david@botton.com> wrote in message 
news:4f4cd4b1-0a6d-441b-a4f7-98add70e4e1e@googlegroups.com...
> Given:
>
>   function Token_Start (Source : in out Awesome.Source.Source_Type'Class)
>                         return Character;
>   function Token_End (Source : in out Awesome.Source.Source_Type'Class)
>                       return String;
>
> The following works:
>
>   function Get_Token_Text (Source : in out 
> Awesome.Source.Source_Type'Class)
>                            return String
>   is
>      N : Character := Token_Start (Source);
>   begin
>      return N & Token_End (Source);
>   end Get_Token_Text;
>
> The following does not work:
>
>   function Get_Token_Text (Source : in out 
> Awesome.Source.Source_Type'Class)
>                            return String
>   is
>   begin
>      return Token_Start (Source) & Token_End (Source);
>   end Get_Token_Text;
>
> Token_End is never called and only the value of Token_Start.

I would have expected this second expression to be illegal, because it seems 
to violate 6.4.1(6.18-19/3). That rule was introduced in Ada 2012 along with 
"in out" function parameters to avoid "obvious" dependence on order of 
evaluation.

The rule is:

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.

(Here C is "&", N is Source, and C2 is Token_Start; the rule says that 
Source can't appear outside of the call of Token_Start, and it does. I'd 
suggest filing a bug report.)

                            Randy.


  parent reply	other threads:[~2015-06-14  3:10 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12 15:56 Is this a bug in my code or the compiler? David Botton
2015-06-12 16:15 ` Dmitry A. Kazakov
2015-06-12 17:25   ` G.B.
2015-06-12 18:00     ` Dmitry A. Kazakov
2015-06-13 10:04       ` Georg Bauhaus
2015-06-13 10:32         ` Dmitry A. Kazakov
2015-06-15 10:37           ` G.B.
2015-06-15 12:27             ` Dmitry A. Kazakov
2015-06-15 12:31               ` Simon Wright
2015-06-15 13:16                 ` Dmitry A. Kazakov
2015-06-15 14:56                   ` Simon Wright
2015-06-15 15:03                     ` G.B.
2015-06-13 19:42       ` Brad Moore
2015-06-12 17:53   ` David Botton
2015-06-12 18:11     ` Dmitry A. Kazakov
2015-06-12 18:43       ` marciant
2015-06-12 19:37     ` Jeffrey R. Carter
2015-06-12 19:55       ` Simon Wright
2015-06-12 20:40         ` Jeffrey R. Carter
2015-06-12 21:40           ` Simon Wright
2015-06-12 19:39     ` jan.de.kruyf
2015-06-12 22:10       ` David Botton
2015-06-13  0:19         ` Dennis Lee Bieber
2015-06-13 14:21         ` jan.de.kruyf
2015-06-14  3:13     ` Randy Brukardt
2015-06-14  3:21     ` Randy Brukardt
2015-06-12 16:48 ` Jeffrey R. Carter
2015-06-13 13:33 ` Jacob Sparre Andersen
2015-06-13 15:15   ` J-P. Rosen
2015-06-13 16:43     ` Jacob Sparre Andersen
2015-06-13 20:50       ` J-P. Rosen
2015-06-14  3:18   ` Randy Brukardt
2015-06-14  3:10 ` Randy Brukardt [this message]
2015-06-14  9:02   ` Jacob Sparre Andersen
2015-06-14 12:48     ` brbarkstrom
2015-06-15 22:06     ` Randy Brukardt
replies disabled

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