comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Language lawyer question: access discriminants
Date: Wed, 7 Apr 2010 15:04:31 -0500
Date: 2010-04-07T15:04:31-05:00	[thread overview]
Message-ID: <hpiogg$fnb$1@munin.nbi.dk> (raw)
In-Reply-To: 06e780ef-c171-4037-b96e-f44788ae2bdf@g10g2000yqh.googlegroups.com

"Adam Beneschan" <adam@irvine.com> 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.





  reply	other threads:[~2010-04-07 20:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-06 21:17 Language lawyer question: access discriminants Adam Beneschan
2010-04-07 20:04 ` Randy Brukardt [this message]
2010-04-08  0:21   ` Adam Beneschan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox