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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: accessibility check failed Date: Sun, 29 Nov 2015 20:15:57 +0100 Organization: cbb software GmbH Message-ID: <1aslcq85i1z8f$.1rbttnghr6xqb$.dlg@40tude.net> References: <3d45e3ed-16ca-4018-bf7b-62830acaca03@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: Sfz0eNwKWh4Uq03iti+GMw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:28596 Date: 2015-11-29T20:15:57+01:00 List-Id: On Sun, 29 Nov 2015 10:03:25 -0800 (PST), Serge Robyns wrote: > I'm facing a "mysterious" accessibility check failed error. Nothing mysterious anonymous access + checks is an endless source of problems in Ada. > I'm having the following function: > > overriding function Get_Client > (Self : not null access T_Data_Store; > Client_Name : in T_Client_Name) > return T_Client'Class > is > Cursor : Client_Map.Cursor; > begin > Cursor := Self.Clients.Find (Client_Name); > if Cursor = Client_Map.No_Element then > return T_Client_DAO'(No_Client > with Store => Self); Try Self.all'Unchecked_Access. (Don't feel guilty about Unchecked_Access, all means are good in the holly war against evil access checks... (:-)) > Researching the web for the accessibility check failed all refers to > returning a reference to a local variable which is indeed disappearing on > the execution of the return statement. But in my case, I'm just storing > the reference I did receive from the parent. Yes, but how much up you pass that reference? The rules are too crude. Most of alarms they generate are false alarms. I don't remember a case accessibility check indeed helped to detect a bug. > I did find a suggestion to replace anonymous access types to named ones > but that does not compile for the interface class for which the above > function is an implementation. It is a poor advice when you design a reusable component. Anonymous access type is the most general type of reference imposing least constraint on the clients. Thus it is the type to be used in all interfaces. In the implementations a named access type is indeed the best and safest choice. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de