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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f0be8eebb2993001 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder2.cambriumusenet.nl!feeder3.cambriumusenet.nl!feed.tweaknews.nl!138.195.8.3.MISMATCH!news.ecp.fr!news.jacob-sparre.dk!pnx.dk!jacob-sparre.dk!ada-dk.org!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Ada 2012 : aliased parameters ? Date: Mon, 25 Apr 2011 02:19:35 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <87aafgerez.fsf@mid.deneb.enyo.de> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1303715982 23706 69.95.181.76 (25 Apr 2011 07:19:42 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Mon, 25 Apr 2011 07:19:42 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5931 X-RFC2646: Format=Flowed; Original Xref: g2news1.google.com comp.lang.ada:19042 Date: 2011-04-25T02:19:35-05:00 List-Id: "Florian Weimer" wrote in message news:87aafgerez.fsf@mid.deneb.enyo.de... >* Randy Brukardt: > >> The motivating case is to make the containers better. Ada 2012 adds the >> following to all of the containers: >> >> function Reference (Container : aliased in out Vector; Position : in >> Cursor) >> return Reference_Type; >> >> where Reference_Type is defined as: >> >> type Reference_Type (Element : not null access Element_Type) is >> private >> with >> Implicit_Dereference => Element; > > Is it necessary that Element is a discriminant? Yes, because access discriminants have special accessibility rules which happen to have the right effect. > If the aliased business works with fields, you could write something like > this: > > type String_Reference is record > Data : access String; > end record; You can write this, but you lose all accessibility checking if you do. The accessibility of a normal component is that of the type, which is typically library level. OTOH, a discriminant in a returned object has the accessibility of the point of call; combined with the rules for aliased parameters, such a discriminant will always succeed (no runtime checks or overhead needed) and will always be safe (can't copy it into anything with a longer lifetime, which is essentially anything). I'm no fan of accessibility checks, but in this case at least they don't get in the way beyond preventing operations that we don't want to allow in the first place. >In any case, it seems to me that the definition of "master" in 7.6.1 needs >updating. It did, but only for bugs. The access discriminant semantics is from Ada 95, although it was never defined properly (probably still isn't, although not for the lack to trying). We've just found a good use for the strange semantics. Randy.