comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Is this legal?
Date: Mon, 18 Oct 2021 22:50:52 -0500	[thread overview]
Message-ID: <sklfau$h0t$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: 6c49980a-fe55-4cea-a356-d021b417d942n@googlegroups.com


"Simon Belmont" <sbelmont700@gmail.com> wrote in message 
news:6c49980a-fe55-4cea-a356-d021b417d942n@googlegroups.com...
>I'm trying to learn the 2012 changes to accessibility rules, ...
...
>Does anyone know off hand which is the correct behavior?

I can assure you that no one anywhere will *ever* know "off-hand" the 
correct behavior. :-) It takes quite a bit of looking to be sure.

...
...
>   function F (y : aliased in out str5) return access str5 is
>   begin
>      return y'Access;
>   end F;

This is always legal (we hope :-). There should be a static (or dynamic) 
check on Y when F is called that Y has an appropriate lifetime for the 
result. (I can't grok "accessibility", either. I always think in terms of 
lifetimes, and then try to translate to the wording.)

>   procedure P (x : in out T) is
>   begin
>      x.current := F(x.foo);
>   end P;

This should always be statically illegal. X here has the lifetime of P (as 
the actual lifetime is unknown). That's not long enough regardless of how 
you declare Current (since it's type is necessarily outside of P). There is 
no special accessibility rules for anonymous access components (unlike most 
other cases); they always have the accessibility (think lifetime) of the 
enclosing type.

My understanding is that AdaCore has been actively working on 
re-implementing these rules correctly, and in a few cases we've changed the 
rules as it was obvious that a better rule was possible (so Ada 2022 changes 
this some more). But none of the Ada 2022 changes should change this 
example.

                                    Randy. 


  parent reply	other threads:[~2021-10-19  3:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-16 19:00 Is this legal? Simon Belmont
2021-10-17  8:35 ` Gautier write-only address
2021-10-17  8:41 ` AdaMagica
2021-10-17 18:31   ` Simon Belmont
2021-10-18 10:50     ` AdaMagica
2021-10-19  3:50 ` Randy Brukardt [this message]
  -- strict thread matches above, loose matches on Subject: below --
1991-11-09 18:02 Is this legal ? Bud Bach
1991-11-09  3:20 Robert I. Eachus
1991-11-08 20:58 Boris Pelakh
replies disabled

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