From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=BAYES_00,XPRIO autolearn=no autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Is this legal? Date: Mon, 18 Oct 2021 22:50:52 -0500 Organization: JSA Research & Innovation Message-ID: References: <6c49980a-fe55-4cea-a356-d021b417d942n@googlegroups.com> Injection-Date: Tue, 19 Oct 2021 03:50:54 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="17437"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:63030 List-Id: "Simon Belmont" 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.