!standard 6.5 (18) 03-05-22 AI95-00316/02 !class ramification 02-10-03 !status Amendment 200Y 03-02-18 !status ARG Approved 8-0-0 03-02-09 !status work item 02-10-03 !status received 02-10-03 !qualifier Omission !priority Medium !difficulty Easy !subject Return accessibility checks and value conversions !summary 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. !question Consider the following generic: generic type T (<>) is limited private; C : in out T; package Gen is type Nt is new T; function Input return Nt; end Gen; package body Gen is function Input return Nt is begin return Nt (C); --Raises Program_Error? (No.) end Input; end Gen; 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. !response 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. !corrigendum 6.5(18) @drepl @xbullet that denotes an object view whose accessibility level is not deeper than that of the master that elaborated the function body; or> @dby @xbullet 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> !ACATS test This case occurs in CD10002, which provides an adequate test. !appendix 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.) ***********************************************************