From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: GCC 11 bug? lawyer needed Date: Thu, 6 May 2021 22:51:43 +0200 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: 5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader02.eternal-september.org comp.lang.ada:61963 List-Id: On 2021-05-06 22:02, Simon Wright wrote: > "Randy Brukardt" writes: > >> I agree that the original author of that program should not have used >> "aliased" in the way that they did (they don't need the special semantics), >> but we realize that some people would prefer to *explicitly* mark things as >> aliased when they are going to take 'Access (and not worry about the type of >> the parameter -- after all, it could change). That is, they don't want to >> depend on the implicit behavior of tagged types -- or perhaps they don't >> even know about it. Which leads to the problem that occurs here, as >> "aliased" has slightly different meanings for functions (now just composite >> functions) and procedures. > > The original code, from the Alire project, had (I've edited it slightly) > > package Holders > is new Ada.Containers.Indefinite_Holders (Node'Class); > > type Tree is > new Holders.Holder > and ... > > function Root (This : Tree) return Node'Class is > (This.Constant_Reference); > > where that Constant_Reference is inherited (eventually) from > Ada.Containers.Indefinite_Holders.Holder, > > function Constant_Reference > (Container : aliased Holder) return Constant_Reference_Type; > pragma Inline (Constant_Reference); > > Shame it had to be there. > > I've just tried splattering 'aliased' wherever the compiler told me it > was needed; it's now spreading into other packages. Ugh. > > The solution might just be using composition rather than inheritance. In my experience mixing handles with target types does not work anyway regardless accessibility rules mess. I tend to use interfaces instead: type Abstract_Node_Interface is interface ...; Then both the handle and the target type implement Abstract_Node_Interface. The target type goes into hiding, the client need not to see it. This requires manual delegation in all primitive operations of handles: dereference + call. But in the end it pays off. Especially with trees, because in mutator operations I can check the reference count of the node and choose to clone it (and maybe the subtree) if there are multiple external handles to it. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de