Version 1.6 of ais/ai-00043.txt

Unformatted version of ais/ai-00043.txt version 1.6
Other versions for file ais/ai-00043.txt

!standard 12.05 (08)          00-04-11 AI95-00043/05
!class binding interpretation 95-06-25
!status Corrigendum 2000 99-07-28
!status WG9 approved 95-06-14
!status ARG approved (subject to editorial review) 8-0-3 95-11-01
!status received 95-06-25
!qualifier Error
!subject Predefined Operators for Generic Formal Array Types
!summary
For a generic formal type whose properties depend on a partial view, (for example, a formal array type whose component type is a private type), the rules of 7.3.1 apply. Thus, the primitive subprograms of the formal type are not necessarily declared immediately after its declaration.
!question
There is an inconsistency between paragraphs 7.3.1(3) and 12.5(8) regarding predefined operators for formal array types in some rare cases. The former says that additional predefined operators may be declared when additional characteristics of the component type become known, whereas 12.5(8) says that all predefined operators are declared immediately after the formal type declaration.
Example:
package P is pragma Elaborate_Body; -- just to make its body legal
type Pt is private;
generic type Ft is array( 1 .. 9 ) of Pt; package G is end G;
private type Pt is new Boolean; end P;
package body P is
package body G is -- relational operators declared for Ft here ? -- 12.5(8) says no, 7.3.1(3) says yes end G;
end P;
(A similar example could be made using a public generic child unit to P, in which case the relational operators would (?) be declared when entering the private part of the public child).
!recommendation
For a generic formal type whose properties depend on a partial view, (for example, a formal array type whose component type is a private type), the rules of 7.3.1 apply. Thus, the primitive subprograms of the formal type are not necessarily declared immediately after its declaration.
!wording
(See corrigendum.)
!discussion
7.3.1(3) and 12.5(8) are in conflict for generic formal types. 7.3.1(3) should take precedence, since otherwise the privacy of private types would be violated. Furthermore, this interpretation is compatible with Ada 83.
!corrigendum 12.05(8)
Replace the paragraph:
The formal type also belongs to each class that contains the determined class. The primitive subprograms of the type are as for any type in the determined class. For a formal type other than a formal derived type, these are the predefined operators of the type; they are implicitly declared immediately after the declaration of the formal type. In an instance, the copy of such an implicit declaration declares a view of the predefined operator of the actual type, even if this operator has been overridden for the actual type. The rules specific to formal derived types are given in 12.5.1.
by:
The formal type also belongs to each class that contains the determined class. The primitive subprograms of the type are as for any type in the determined class. For a formal type other than a formal derived type, these are the predefined operators of the type. For an elementary formal type, the predefined operators are implicitly declared immediately after the declaration of the formal type. For a composite formal type, the predefined operators are implicitly declared either immediately after the declaration of the formal type, or later in its immediate scope according to the rules of 7.3.1. In an instance, the copy of such an implicit declaration declares a view of the predefined operator of the actual type, even if this operator has been overridden for the actual type. The rules specific to formal derived types are given in 12.5.1.
!ACATS test
Create a C-Test as in the example in this ruling. It should try to use added operators.
!appendix

!section 12.5(8)
!section 7.3.1(3)
!subject Predefined Operators for Generic Formal Array Types
!reference AARM-12.5(8);6.0
!reference AARM-7.3.1(3);6.0
!from Jesper Joergensen 95-04-26
!reference as: 95-5129.a Jesper Joergensen 95-4-26>>
!discussion

It seems to me there is an inconsistency between the paragraphs 7.3.1(3) and
12.5(8) regarding predefined operators for formal array types in some rare
cases. The former says that additional predefined operators may be declared
when additional characteristics of the component type becomes known, whereas
12.5(8) says that all predefined operators are declared immediately after the
formal type declaration.

Example:

   package P is
      pragma Elaborate_Body;   -- just to make its body legal

      type Pt is private;

      generic
         type Ft is array( 1 .. 9 ) of Pt;
      package G is
      end G;

   private
      type Pt is new Boolean;
   end P;


   package body P is

      package body G is
         -- relational operators declared for Ft here ?
         -- 12.5(8) says no, 7.3.1(3) says yes
      end G;

   end P;


(A similar example could be made using a public generic child unit to P, in
which case the relational operators would (?) be declared when entering the
private part of the public child).

Maybe 7.3.1(3) was not intended to cover the formal array types or maybe I have
simply overlooked something. What was the intention?

/Jesper


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

Questions? Ask the ACAA Technical Agent