Version 1.5 of ai05s/ai05-0203-1.txt

Unformatted version of ai05s/ai05-0203-1.txt version 1.5
Other versions for file ai05s/ai05-0203-1.txt

!standard 3.9.3(8/3)          10-06-06 AI05-0203-1/03
!class binding interpretation 10-02-13
!status Amendment 2012 10-04-02
!status WG9 Approved 10-06-18
!status ARG Approved 10-0-0 10-02-28
!status work item 10-02-13
!status received 09-09-24
!priority Low
!difficulty Easy
!qualifier Omission
!subject A return_subtype_indication cannot denote an abstract subtype
!summary
A return_subtype_indication cannot denote an abstract subtype.
!question
There seems to be a loophole regarding abstract types and return statements. Suppose the type Abstract_Type is declared to be an abstract type and consider
function Func return Abstract_Type'Class is begin return X : Abstract_Type; end Func;
This clearly has to be illegal since we cannot return a value of an abstract type. However, nothing in 3.9.3(8) applies to this {since it's not an object_declaration).
!recommendation
(See Summary.)
!wording
Add after the fifth sentence of 3.9.3(8/3) (as modified by AI05-0073-1):
The type denoted by a return_subtype_indication (see 6.5) shall not be abstract.
!discussion
In the example in the question, the function appears to be currently legal because it is returning a class-wide type, which is never abstract (3.9.3(1.2/2)). Since any type that is covered by the class-wide type is allowed in the extended_return_statement, we could use a specific abstract type as shown. So we need to explicitly disallow this case.
!corrigendum 3.9.3(8/3)
Replace the paragraph:
The type of an aggregate, or of an object created by an object_declaration or an allocator, or a generic formal object of mode in, shall not be abstract. The type of the target of an assignment operation (see 5.2) shall not be abstract. The type of a component shall not be abstract. If the result type of a function is abstract, then the function shall be abstract. If a function has an access result type designating an abstract type, then the function shall be abstract. A generic function shall not have an abstract result type or an access result type designating an abstract type.
by:
The type of an aggregate, or of an object created by an object_declaration or an allocator, or a generic formal object of mode in, shall not be abstract. The type of the target of an assignment operation (see 5.2) shall not be abstract. The type of a component shall not be abstract. If the result type of a function is abstract, then the function shall be abstract. If a function has an access result type designating an abstract type, then the function shall be abstract. The type denoted by a return_subtype_indication (see 6.5) shall not be abstract. A generic function shall not have an abstract result type or an access result type designating an abstract type.
!ACATS Test
An ACATS B-Test should be created that checks this rule.
!appendix

!topic Extended return with abstract type??
!reference 3.9.3(8), 6.5
!from Adam Beneschan 09-11-24
!discussion

One more for the "abstract screwups" AI (AI05-73), maybe:

I can't find anything in 3.9.3(8) or 6.5 that makes this illegal,
although surely it must be:

   function Func return Abstract_Type'Class is
   begin
      return X : Abstract_Type;
   end Func;

Nothing in 3.9.3(8) applies to this (since it's not an
object_declaration). 

****************************************************************

From: Edmond Schonberg
Sent: Tuesday, November 24, 2009  2:01 PM

Well, there is 3.1 (6/2) ... " In addition, an
extended_return_statement is a declaration of its defining  
identifier"   but this is rather oblique, and does not correspond  
explicitly to the categories described in 3.9.3 (8).

****************************************************************

Questions? Ask the ACAA Technical Agent