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,187ddf41516e5d0b X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!eweka.nl!hq-usenetpeers.eweka.nl!proxad.net!feeder1-2.proxad.net!u-picardie.fr!news.ecp.fr!news.jacob-sparre.dk!pnx.dk!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Language lawyer question: access discriminants Date: Wed, 7 Apr 2010 15:04:31 -0500 Organization: Jacob Sparre Andersen Message-ID: References: <06e780ef-c171-4037-b96e-f44788ae2bdf@g10g2000yqh.googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1270670672 16107 69.95.181.76 (7 Apr 2010 20:04:32 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Wed, 7 Apr 2010 20:04:32 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5843 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-RFC2646: Format=Flowed; Original Xref: g2news1.google.com comp.lang.ada:9918 Date: 2010-04-07T15:04:31-05:00 List-Id: "Adam Beneschan" wrote in message news:06e780ef-c171-4037-b96e-f44788ae2bdf@g10g2000yqh.googlegroups.com... > I'm hoping someone who understands the rules about access discriminant > accessibility level can answer this definitively. You're assuming such a person exists. I'm dubious. :-) > This is a reduced > example of something I found in someone else's code: > > package Pack1 is > type Rec is record > F1 : Integer; > end record; > type Rec2 (D : access Rec) is limited record > F2 : Integer; > end record; > function Func (Param : Integer) return Rec2; > end Pack1; > > with Pack1; use Pack1; > procedure Proc2 is > A : access Rec; > begin > A := Func(1).D; -- LEGAL? > end Proc2; This program is depending on the accessibility of access discriminants of an object returned from a function. Those are not currently defined. We know that the rules as defined in Ada 2005 don't work (have various nasty holes). The rules corrections proposed by AI05-0051-1 have never been approved, and so far as I know, are only understood by the author (Tucker Taft). My (lousy) understanding of the rules proposed in AI05-0051-1 is that the accessibility of the access discriminants of the returned object are that of the call site. The rules Tucker proposed would generally cause the accessibility of the LHS of the assignment to propagate into the function, and a (dynamic) check would be made at the return statement that the accessibility is sufficient. The net effect is that this call is always legal, but it is very likely that it would fail an accessibility check at the return statement -- thus it would usually raise Program_Error. > I think the statement marked LEGAL? is illegal, because of rules > saying that the result of Func is an object inside a nested master > that consists of just the one assignment statement, and the > accessibility level of the access discriminant (Func(1).D) is the > accessibility level of the enclosing object (the temporary object > containing the result of Func), and therefore the accessibility level > of Func(1).D is deeper than that of A. But the rules are pretty > complex and I'm hoping someone in the know can straighten me out if > I'm wrong. (And I'm not interested in any replies that say "XYZ > compiler says it's legal". I need to know what the standard says.) What I can't say for sure is whether the accessibility of the LHS would be used or whether that of a assignment statement would be used. I'd have to go and read the AI again several times and even then I wouldn't really know for sure. I do know that type conversions get the right accessibility (so using a named type here and a type conversion would surely be legal). But remember this is all based on the unapproved binding interpretation AI05-0051-1. What the standard says currently is garbage, and it isn't worth figuring out what those rules are (no one will ever try to enforce those - that is, no ACATS test will ever exist for the rules as currently written). So my best advice is do whatever you want now, and plan to adjust to AI05-0051-1 rules when (if?) that gets finished. Randy.