comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Containers, dangling references
Date: Mon, 9 Mar 2020 18:19:29 -0500
Date: 2020-03-09T18:19:29-05:00	[thread overview]
Message-ID: <r46iu2$6b2$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: lya74pbhro.fsf@pushface.org

"Simon Wright" <simon@pushface.org> 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.


  reply	other threads:[~2020-03-09 23:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-09 16:43 Containers, dangling references Simon Wright
2020-03-09 23:19 ` Randy Brukardt [this message]
2020-03-10 18:07   ` Simon Wright
2020-03-10 20:28     ` 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