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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.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: Containers, dangling references Date: Mon, 9 Mar 2020 18:19:29 -0500 Organization: JSA Research & Innovation Message-ID: References: Injection-Date: Mon, 9 Mar 2020 23:19:30 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="6498"; 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: reader01.eternal-september.org comp.lang.ada:58182 Date: 2020-03-09T18:19:29-05:00 List-Id: "Simon Wright" wrote in message news:lya74pbhro.fsf@pushface.org... ... > with implementation > > function Reference (C : aliased in out Container; Position : in Cursor) > return Reference_Type > is > pragma Unreferenced (C); > begin > return (Element => Position.The_Node.all.The_Element'Access, Dummy => > 1); > end Reference; The language rules are designed to allow returning part of an aliased parameter as the return from a function. But one could also return a part of the designated object of a library-level access type. Thus, what matters here is the type declaration of "The_Node", which would need to be a library-level access type (or at least instance-level) in order of this to work. I note this implementation is missing the check that the cursor is for an element in the provided container (and isn't null). Perhaps you simplified the implementation for this presentation. This sort of expression is a tough one to deal with for compilers. Janus/Ada used to (and maybe still does :-) have problems with the accessibility of expressions that have multiple access types. It would use the wrong type to determine the accessibility. Perhaps something similar is happening for GNAT. It's also suspicious that the explicit .all changes the result from the implicit .all. That suggests a bug more than an intended implementation. Randy.