Version 1.4 of ais/ai-00316.txt
!standard 6.5 (18) 03-05-22 AI95-00316/02
!class ramification 02-10-03
!status Amendment 200Y 03-02-18
!status WG9 approved 03-06-20
!status ARG Approved 8-0-0 03-02-09
!status work item 02-10-03
!status received 02-10-03
!subject Return accessibility checks and value conversions
6.5(18) applies to any type conversion (including value conversions) that
can be used as the return expression for a return-by-reference type.
Consider the following generic:
type T (<>) is limited private;
C : in out T;
package Gen is
type Nt is new T;
function Input return Nt;
package body Gen is
function Input return Nt is
return Nt (C); --
type R (D : access Integer) is limited null record;
C : R (new Integer'(19));
package Inst is new Gen (T => R,
C => C);
R is an untagged return-by-reference type by 6.5(14); therefore T and Nt
are untagged return-by-reference types. Nt(C) is a value conversion by
4.6(5/1). Does 6.5(18) apply to this name? (Yes.) The name does not appear
to be an "object view". If 6.5(18) does not apply, 6.5(19) does not
apply either and Program_Error must be raised.
This is covered by 6.2(10): Each value of a by-reference type has an
associated object. For a ... type_conversion, this object is the one associated
with the operand.
Since all return-by-reference types are also by-reference types (compare
6.2(4-9) with 6.5(11-16)), 6.2(10) applies to all return-by-reference
expressions. Thus all such expressions have an associated object to which
the accessibility check of 6.5(18) can be applied.
We add a parenthetical remark to 6.5(18) in order to make this clear.
Replace the paragraph:
- a name that denotes an object view whose accessibility level is
not deeper than that of the master that elaborated the function body; or
- a name that denotes an object view (or a value with an associated
object, see 6.2) whose accessibility level is not deeper than that of the
master that elaborated the function body; or
This case occurs in CD10002, which provides an adequate test.
From: Randy Brukardt
Sent: Thursday, October 3, 2002 5:22 PM
I tried a test version of the code in the question on all of the Ada compilers
I have access to. All of them (Janus/Ada 3.1.2, GNAT 3.15a, Aonix 7.2.1, and
Rational Apex 3.2.0c) ran the program without raising Program_Error. It seems
likely that real users have code like this.
Therefore, I suggest that we declare this legal by relying on 6.2(10). Any
compilers which assumes that 6.5(18) does not apply can be changed without any
significant impact on their users.
(Note that in this interpretation 6.5(19) is not needed. A more radical change
eliminates 6.5(19) completely, and combines 6.5(17 and 18). This probably
would be the better approach in a revision, but it would mean that the
ACATS test in question could be disputed until the revision was approved. I
am not in favor of that result.)
Questions? Ask the ACAA Technical Agent