CVS difference for ais/ai-00326.txt

Differences between 1.8 and version 1.9
Log of other versions for file ais/ai-00326.txt

--- ais/ai-00326.txt	2004/01/08 04:16:39	1.8
+++ ais/ai-00326.txt	2004/01/23 04:59:28	1.9
@@ -1,19 +1,26 @@
-!standard 03.10.01   (02)                            03-12-11  AI95-00326/05
+!standard 03.02      (04)                            04-01-09  AI95-00326/06
+!standard 03.02      (05)
+!standard 03.07      (01)
+!standard 03.10.01   (02)
 !standard 03.10.01   (04)
 !standard 03.10.01   (05)
 !standard 03.10.01   (08)
 !standard 03.10.01   (09)
 !standard 03.10.01   (10)
 !standard 03.10.01   (11)
+!standard 10.01.01   (12)
+!standard 13.01      (11/1)
 !standard J.11       (00)
 !class amendment 02-02-06
+!status Amendment 200Y 04-01-09
+!status ARG Approved 10-0-3  03-12-12
 !status work item 03-07-30
 !status ARG Approved 10-0-1  03-07-15
 !status work item 02-12-13
 !status received 02-02-06
 !priority Medium
 !difficulty Medium
-!subject Tagged incomplete types
+!subject Incomplete types
 
 !summary
 
@@ -86,7 +93,7 @@
   of 7.3(4) gets square brackets in the RM (but I'd recommend leaving it there
   in order to keep the entire private type model intact).
 
-Modify 3.7(1) to remove the two occurrences of "partial" in the second sentence.
+Modify 3.7(1) to remove the two occurrences of "partial" in the last sentence.
 
 Note: Incomplete views can have unknown_discriminant_parts, and this wording
   should reflect that. Since full views cannot have unknown_discriminant_parts,
@@ -99,14 +106,11 @@
 
 Modify 3.10.1(4):
 
-Add two new first sentences:
+Add a new first sentence:
 
   If an incomplete_type_declaration includes the keyword TAGGED, then the
-  type_declaration that completes it shall declare a tagged type. Such an
-  an incomplete_type_declaration declares a tagged incomplete view.
+  full_type_declaration that completes it shall declare a tagged type.
 
-In the other sentences, replace "full_type_declaration" with "type_declaration".
-
 Replace 3.10.1(5-9):
 
   A name that denotes an incomplete view of a type may be used as follows:
@@ -115,7 +119,7 @@
       access_to_object_definition; the only form of constraint allowed in
       this subtype_indication is a discriminant_constraint;
 
-    * as the subtype_mark in an access_definition;
+    * as the subtype_mark in an access_definition.
 
   If such a name denotes a tagged incomplete view, it may also be used:
 
@@ -130,7 +134,7 @@
   the completion of the incomplete view, it may also be used:
 
     * as the subtype_mark defining the subtype of a parameter or result of
-      an access_to_subprogram_definition;
+      an access_to_subprogram_definition.
 
   If any of the above uses occurs as part of the declaration of a primitive
   subprogram of the incomplete view, and the declaration occurs immediately
@@ -154,23 +158,24 @@
 will preclude their use except when the full type is "nearby" as context
 (e.g. as the expected type).
 
-TBD: What about assignment statements?  Is an incomplete type limited
-or nonlimited?
-
 Replace 3.10.1(11):
 
    An incomplete_type_declaration declares an incomplete view of a type,
    and its first subtype; the first subtype is unconstrained if a
-   known_discriminant_part appears.
+   known_discriminant_part appears. If the incomplete_type_declaration includes
+   the keyword TAGGED, it declares a tagged incomplete view. An incomplete
+   view of a type is a limited view of the type (see 7.5).
 
-AARM Change: We define "incomplete view" here.
+AARM Change: We define "incomplete view" and "tagged incomplete view" here.
+We explicitly say that "incomplete view"s do not have assignment.
 
   Given an access type A whose designated type T is an incomplete view,
-  a dereference of a value of type A is also of this incomplete view
+  a dereference of a value of type A also has this incomplete view
   except when:
     * it occurs in the immediate scope of the completion of T, or
     * it occurs in the scope of a nonlimited_with_clause that mentions
       a library package in whose visible part the completion of T is declared.
+  In these cases, the dereference has the full view of T.
 
 AARM Note: We need the "in whose visible part" rule so that
   the second rule doesn't trigger in the body of a package with a with of a
@@ -179,11 +184,11 @@
    package P is
    private
       type T;
-      type AT is access T;
+      type PtrT is access T;
    end P;
 
    private package P.C is
-      Ptr : AT;
+      Ptr : PtrT;
    end P.C;
 
    with P.C;
@@ -194,41 +199,20 @@
        -- Ptr.all is legal here.
    end P;
 
-AI-217 Note: The above rules comes from AI-217-06. Note that here we say that
+AI-217 Note: The above rules come from AI-217-06. Note that here we say that
   the view is complete, and thus none of the restrictions outlined in this
-  section apply, not just dereferencing as the AI-217-6 wording said. I believe
-  that is what was intended (it certainly is what *I* thought was intended).
+  section apply, not just dereferencing as the AI-217-6 wording said. That
+  is what was intended by AI-217-06 (the wording was faulty).
 
-  A dereference (whether implicit or explicit -- see 4.1) shall not be
-  of an incomplete view, unless:
-    * its expected type is not an incomplete view of T;
-
-AARM Note: This means that it is a partial or full view of T. We don't
-enumerate the kinds of views to make it easier to add other kinds of views in
-the future.
-
-AI-217 Note: This also comes from AI-217.
-
-    * it is a tagged incomplete view and it is used as an actual parameter of a
-      call, or the expression of a qualified_expression or parenthesized
-      expression used in one of these contexts.
-
-AARM Note: Dispatching calls are prohibited for incomplete views (see 3.9.2),
-so this is mainly useful in class-wide calls.
-
-AARM To Be Honest: This really means "top-level" actual parameter with arbitrary
-qualified_expressions and parents. We can't allow it to occur as the operand
-of a type conversion, membership operation, or predefined equality. Since
-equality is a function, it is already covered by these rules, but the other
-cases aren't.
-
-*** Open issue: Alternative wording could say "...it is used in the expression
-or name of an actual parameter of a call, but not as the operand of a type
-conversion or membership operation." But that brings up the possibility of
-missing a problem case.
-
 4.1(9): No change is needed. Note that this differs from the proposed AI-217-6.
 
+The second bullet of the new text following 10.1.1(12) from AI-217-6 should
+read:
+
+  *  For each type_declaration in the visible part, an incomplete view of
+     the type is declared. If the type_declaration is tagged, then the view
+     is a tagged incomplete view.
+
 Modify 13.1(11/1):
 
   Replace the second sentence by:
@@ -243,7 +227,7 @@
 
 Add J.11:
 
-   J.11 The Class Attribute of Non-tagged Incomplete Types
+   J.11 The Class Attribute of Untagged Incomplete Types
 
    For the first subtype S of a type T declared by an
    incomplete_type_declaration that is not tagged, the
@@ -297,14 +281,14 @@
       type T1;
       type AT1 is access all T1'Class;
       P1 : AT1;
+      procedure Foo (P : access T1); -- OK in Ada 95.
       type T2 is tagged;
       type AT2 is access all T2'Class;
       P2 : AT2;
+      procedure Bar (P : T2);
     end P;
 
     private package P.C is
-      procedure Foo (P : access T1);
-      procedure Bar (P : T2);
       procedure Test;
     end P.C;
 
@@ -318,11 +302,14 @@
 
 If the body of P sets P1 and P2 to objects, the calls to Foo and Bar are
 dispatching calls and logically ought to work. But the location of the
-tags for T1 and T2 are unknown when the calls are compiled. Therefore, we
-add a rule to make dispatching calls when the dispatching type is incomplete
-illegal.
+tags for T1 and T2 are unknown when the calls are compiled.
+
+This hole is fixed by adding a rule which prevents the completion of an
+incomplete type from being deferred to the body if the type has any primitive
+operations. Thus types T1 and T2 are missing completions in the example
+above, and the example is therefore illegal.
 
-Dereferences of incomplete tagged types are still be useful for class-wide
+Dereferences of incomplete tagged types are still useful for class-wide
 calls. For instance (presuming AI-217-6 is approved):
 
     limited with Departments;
@@ -330,6 +317,7 @@
        type Employee is private;
        procedure Assign (E : Employee; D : Departments.Department'Class);
        type Dept_Ptr is access Departments.Department'Class;
+    private ...
     end Employees;
 
     with Employees;
@@ -342,106 +330,290 @@
 that Employees uses and it was passed and is passing along. It would be bizarre
 for Recruit to have to with Departments simply to be able to call Assign.
 
+Ada 95 introduced the rule forbidding all dereferences. However, this turns
+out to be stronger than necessary. The problem cases are those where:
+    * A component of the dereferenced item is read (a discriminant or tag);
+    * A property of the dereferenced item is used (like 'Size);
+    * The dereferenced item is of an untagged type and is passed in a
+      subprogram call (in this case, the parameter passing mechanism --
+      by copy or by reference -- is not known);
+and the complete type is not available.
+The last case is interesting. In order for this to happen, we have to have
+a parameter of an untagged incomplete type which is either deferred to the
+body, or is an incomplete view generated from the limited view of a package.
+Ada 95 allows this only for access-to-subprogram types.
+
+However, being able to dereference access-to-incomplete objects is a useful
+capability, especially when an object of the complete type is available via
+another withing path. It seems better to simply disallow the
+access-to-subprogram case when it happens, especially as it seems to be more
+of an unintended consequence of the rules than an intended use of incomplete
+types.
+
+Thus, we adopt a rule which does not allow incomplete views to be used
+in access-to-subprogram type definitions unless the completion of the
+incomplete type is in the same declaration list. (For such a type, the
+completion would always be available anywhere that an object could be created.)
 
+That means that such types are not allowed if the completion is deferred to
+the body, or for incomplete views from a limited view of a package.
+
+With this rule in hand, we only need to disallow dereferences which are
+prefixes (the first two cases above).
+
 !example
+
+Here is the example from AI-217-6, recast to use the additional capabilities
+of tagged incomplete types. These allow the elimination of the explicit
+access types from the parameters of the subprograms.
+
+Note that the function return still requires an explicit access type, because
+neither tagged incomplete views nor anonymous access types are allowed there.
+
+    limited with Departments;
+    package Employees is
+        type Employee is tagged private;
+        procedure Assign_Employee(E : in out Employee;
+                                  D : in out Departments.Department'Class);
+        type Dept_Ptr is access all Departments.Department'Class;
+        function Current_Department(D : in Employee) return Dept_Ptr;
+        ...
+    end Employees;
 
---*** Will redo the !corrigendum in the future.
---!corrigendum 3.10.1(2)
---
---@drepl
---@xindent<@fa<incomplete_type_declaration ::= @b<type> defining_identifier [discriminant_part];>>
---@dby
---@xindent<@fa<incomplete_type_declaration ::= @b<type> defining_identifier [discriminant_part] [@b<is tagged>];
---
---!corrigendum 3.10.1(4)
---
---@drepl
---If an @fa<incomplete_type_declaration> has a @fa<known_discriminant_part>, then
---a @fa<full_type_declaration> that completes it shall have a fully conforming
---(explicit) @fa<known_discriminant_part> (see 6.3.1). If an
---@fa<incomplete_type_declaration> has no @fa<discriminant_part> (or an
---@fa<unknown_discriminant_part>), then a corresponding @fa<full_type_declaration>
---is nevertheless allowed to have discriminants, either explicitly, or inherited
---via derivation.
---@dby
---If an @fa<incomplete_type_declaration> includes the keyword @b<tagged>, then a
---@fa<type_declaration> that completes it shall declare a tagged type.
---If an @fa<incomplete_type_declaration> has a @fa<known_discriminant_part>, then
---a @fa<type_declaration> that completes it shall have a fully conforming
---(explicit) @fa<known_discriminant_part> (see 6.3.1). If an
---@fa<incomplete_type_declaration> has no @fa<discriminant_part> (or an
---@fa<unknown_discriminant_part>), then a corresponding @fa<type_declaration>
---is nevertheless allowed to have discriminants, either explicitly, or inherited
---via derivation.
---
---!corrigendum 3.10.1(5)
---
---@drepl
---The only allowed uses of a name that denotes an @fa<incomplete_type_declaration>
---are as follows:
---@dby
---A name that denotes an @fa<incomplete_type_declaration> may be used as follows:
---
---!corrigendum 3.10.1(8)
---
---@drepl
---@xbullet<as the @fa<subtype_mark> in an @fa<access_definition>;>
---@dby
---@xbullet<as the @fa<subtype_mark> in an @fa<access_definition>.>
---
---A name that denotes an incomplete_type_declaration that includes the
---keyword @b<tagged> may also be used as follows:
---
---@xbullet<as the @fa<subtype_mark> defining the subtype of a parameter in a
---@fa<formal_part>;>
---
---!corrigendum 3.10.1(9)
---
---@drepl
---@xbullet<as the @fa<prefix> of an @fa<attribute_reference> whose
---@fa<attribute_designator> is Class; such an @fa<attribute_reference> is
---similarly restricted to the uses allowed here; when used in this way, the
---corresponding @fa<full_type_declaration> shall declare a tagged type, and the
---@fa<attribute_reference> shall occur in the same library unit as the
---@fa<incomplete_type_declaration>.>
---@dby
---@xbullet<as the @fa<prefix> of an @fa<attribute_reference> whose
---@fa<attribute_designator> is Class; such an @fa<attribute_reference> is
---restricted to the uses allowed above.>
---
---!corrigendum 3.10.1(10)
---
---@drepl
---A dereference (whether implicit or explicit -- see 4.1) shall not be
---of an incomplete type.
---@dby
---A dereference (whether implicit or explicit -- see 4.1) shall not be
---of an incomplete type, unless it is directly used as an actual
---parameter where the expected type is a class-wide tagged incomplete type.
---
---!corrigendum 3.10.1(11)
---
---@drepl
---An @fa<incomplete_type_declaration> declares an incomplete type and its first
---subtype; the first subtype is unconstrained if a @fa<known_discriminant_part>
---appears.
---@dby
---An @fa<incomplete_type_declaration> declares an incomplete type and its
---first subtype; the incomplete type is tagged if the keyword @b<tagged>
---appears; the first subtype is unconstrained if a @fa<known_discriminant_part>
---appears.
---
---!corrigendum J.11(1)
---
---@dinsc
---For the first subtype S of a type T declared by an
---@fa<incomplete_type_declaration> that is not tagged and is not a type stub, the
---following attribute is defined:
---
---@xhang<@xterm<S'Class>Denotes the first subtype of the incomplete class-wide
---type rooted at T. The completion of T shall declare a tagged type. Such an
---attribute reference shall occur in the same library unit as the
---@fa<incomplete_type_declaration>.
+    limited with Employees;
+    package Departments is
+        type Department is tagged private;
+        procedure Choose_Manager(D : in out Department;
+                                 Manager : in out Employees.Employee'Class);
+        ...
+    end Departments;
+
+!corrigendum 3.2(4)
+
+@drepl
+The composite types are the @i<record> types, @i<record extensions>, @i<array>
+types, @i<task> types, and @i<protected> types. A @i<private> type or
+@i<private extension> represents a partial view (see 7.3) of a type, providing
+support for data abstraction. A partial view is a composite type.
+@dby
+The composite types are the @i<record> types, @i<record extensions>, @i<array>
+types, @i<task> types, and @i<protected> types.
+
+There can be multiple views of a type with varying sets of operations. An
+@i<incomplete> type represents an incomplete view (see 3.10.1) of a type with a
+very restricted usage, providing support for recursive data structures. A
+@i<private> type or @i<private extension> represents a partial view (see 7.3)
+of a type, providing support for data abstraction. The full view (see 3.2.1) of
+a type provides its complete declaration. An incomplete or partial view is
+considered a composite type.
+
+!corrigendum 3.2(5)
+
+@drepl
+Certain composite types (and partial views thereof) have special components
+called @i<discriminants> whose values affect the presence, constraints, or
+initialization of other components. Discriminants can be thought of as
+parameters of the type.
+@dby
+Certain composite types (and views thereof) have special components
+called @i<discriminants> whose values affect the presence, constraints, or
+initialization of other components. Discriminants can be thought of as
+parameters of the type.
+
+!corrigendum 3.2.1(8)
+
+@drepl
+A named type that is declared by a @fa<full_type_declaration>, or an anonymous
+type that is defined as part of declaring an object of the type, is called a
+@i<full type>. The @fa<type_definition>, @fa<task_definition>,
+@fa<protected_definition>, or @fa<access_definition> that defines a full type
+is called a @i<full type definition>. Types declared by other forms of
+@fa<type_declaration> are not separate types; they are partial or incomplete
+views of some full type.
+@dby
+A named type that is declared by a @fa<full_type_declaration>, or an anonymous
+type that is defined as part of declaring an object of the type, is called a
+@i<full type>. A full type defines the @i<full view> of a type. The
+@fa<type_definition>, @fa<task_definition>, @fa<protected_definition>, or
+@fa<access_definition> that defines a full type is called a @i<full type
+definition>. Types declared by other forms of @fa<type_declaration> are not
+separate types; they are partial or incomplete views of some full type.
+
+!corrigendum 3.7(1)
+
+@drepl
+A composite type (other than an array type) can have discriminants, which
+parameterize the type. A @fa<known_discriminant_part> specifies the
+discriminants of a composite type. A discriminant of an object is a component
+of the object, and is either of a discrete type or an access type. An
+@fa<unknown_discriminant_part> in the declaration of a partial view of a type
+specifies that the discriminants of the type are unknown for the given view;
+all subtypes of such a partial view are indefinite subtypes.
+@dby
+A composite type (other than an array type) can have discriminants, which
+parameterize the type. A @fa<known_discriminant_part> specifies the
+discriminants of a composite type. A discriminant of an object is a component
+of the object, and is either of a discrete type or an access type. An
+@fa<unknown_discriminant_part> in the declaration of a view of a type
+specifies that the discriminants of the type are unknown for the given view;
+all subtypes of such a view are indefinite subtypes.
+
+!corrigendum 3.10.1(2)
+
+@drepl
+@xcode<@fa<incomplete_type_declaration ::= >@ft<@b<type>>@fa< defining_identifier [discriminant_part];>>
+@dby
+@xcode<@fa<incomplete_type_declaration ::= >@ft<@b<type>>@fa< defining_identifier [discriminant_part] [>@ft<@b<is tagged>>@fa<];>>
+
+!corrigendum 3.10.1(4)
+
+@drepl
+If an @fa<incomplete_type_declaration> has a @fa<known_discriminant_part>, then
+a @fa<full_type_declaration> that completes it shall have a fully conforming
+(explicit) @fa<known_discriminant_part> (see 6.3.1). If an
+@fa<incomplete_type_declaration> has no @fa<discriminant_part> (or an
+@fa<unknown_discriminant_part>), then a corresponding @fa<full_type_declaration>
+is nevertheless allowed to have discriminants, either explicitly, or inherited
+via derivation.
+@dby
+If an @fa<incomplete_type_declaration> includes the keyword @b<tagged>, then a
+@fa<full_type_declaration> that completes it shall declare a tagged type.
+If an @fa<incomplete_type_declaration> has a @fa<known_discriminant_part>, then
+a @fa<full_type_declaration> that completes it shall have a fully conforming
+(explicit) @fa<known_discriminant_part> (see 6.3.1). If an
+@fa<incomplete_type_declaration> has no @fa<discriminant_part> (or an
+@fa<unknown_discriminant_part>), then a corresponding @fa<full_type_declaration>
+is nevertheless allowed to have discriminants, either explicitly, or inherited
+via derivation.
+
+!corrigendum 3.10.1(5)
+
+@drepl
+The only allowed uses of a name that denotes an @fa<incomplete_type_declaration>
+are as follows:
+@dby
+A name that denotes an incomplete view of a type may be used as follows:
+
+!corrigendum 3.10.1(7)
+
+@ddel
+@xbullet<as the @fa<subtype_mark> defining the subtype of a parameter or
+result of an @fa<access_to_subprogram_definition>;>
+
+!corrigendum 3.10.1(8)
+
+@drepl
+@xbullet<as the @fa<subtype_mark> in an @fa<access_definition>;>
+@dby
+@xbullet<as the @fa<subtype_mark> in an @fa<access_definition>.>
+
+If such a name denotes a tagged incomplete view, it may also be used:
+
+@xbullet<as the @fa<subtype_mark> defining the subtype of a parameter in a
+@fa<formal_part>;>
+
+!corrigendum 3.10.1(9)
+
+@drepl
+@xbullet<as the @fa<prefix> of an @fa<attribute_reference> whose
+@fa<attribute_designator> is Class; such an @fa<attribute_reference> is
+similarly restricted to the uses allowed here; when used in this way, the
+corresponding @fa<full_type_declaration> shall declare a tagged type, and the
+@fa<attribute_reference> shall occur in the same library unit as the
+@fa<incomplete_type_declaration>.>
+@dby
+@xbullet<as the prefix of an @fa<attribute_reference> whose
+@fa<attribute_designator> is Class; such an @fa<attribute_reference> is
+restricted to the uses allowed above for tagged incomplete views.>
+
+If such a name occurs within the list of declarative_items containing
+the completion of the incomplete view, it may also be used:
+
+@xbullet<as the @fa<subtype_mark> defining the subtype of a parameter or result
+of an @fa<access_to_subprogram_definition>.>
+
+If any of the above uses occurs as part of the declaration of a primitive
+subprogram of the incomplete view, and the declaration occurs immediately
+within the private part of a package, then the completion of the incomplete
+view shall also occur immediately within the private part; it may not be
+deferred to the package body.
+
+!corrigendum 3.10.1(10)
+
+@drepl
+A dereference (whether implicit or explicit -- see 4.1) shall not be
+of an incomplete type.
+@dby
+A @fa<prefix> shall not be of an incomplete view.
+
+!corrigendum 3.10.1(11)
+
+@drepl
+An @fa<incomplete_type_declaration> declares an incomplete type and its first
+subtype; the first subtype is unconstrained if a @fa<known_discriminant_part>
+appears.
+@dby
+An @fa<incomplete_type_declaration> declares an @i<incomplete view> of a type,
+and its first subtype; the first subtype is unconstrained if a
+@fa<known_discriminant_part> appears. If the @fa<incomplete_type_declaration>
+includes the reserved word @b<tagged>, it declares a @i<tagged incomplete view>.
+An incomplete view of a type is a limited view of the type (see 7.5).
+
+Given an access type A whose designated type T is an incomplete view,
+a dereference of a value of type A also has this incomplete view
+except when:
+@xbullet<it occurs in the immediate scope of the completion of T, or>
+@xbullet<it occurs in the scope of a nonlimited_with_clause that mentions
+a library package in whose visible part the completion of T is declared.>
+In these cases, the dereference has the full view of T.
+
+!corrigendum 10.1.1(12)
+
+@dinsa
+A @fa<library_unit_declaration> or a @fa<library_unit_renaming_declaration> is
+@i<private> if the declaration is immediately preceded by the reserved word
+@b<private>; it is otherwise @i<public>. A library unit is private or public
+according to its declaration. The @i<public descendants> of a library unit are
+the library unit itself, and the public descendants of its public children. Its
+other descendants are @i<private descendants>.
+
+@dinss
+For each library @fa<package_declaration> in the environment, there is
+an implicit declaration of a @i<limited view> of that library package. The
+limited view of a package contains:
+
+@xbullet<For each nested @fa<package_declaration>, a declaration of the
+limited view of that package, with the same @fa<defining_program_unit_name>.>
+
+@xbullet<For each @fa<type_declaration> in the visible part, an incomplete
+view of the type is declared. If the @fa<type_declaration> is tagged, then the
+view is a tagged incomplete view.>
+
+!corrigendum 13.1(11/1)
+
+@drepl
+Operational and representation aspects of a generic formal parameter are the
+same as those of the actual. Operational and representation aspects of a
+partial view are the same as those of the full view. A type-related
+representation item is not allowed for a descendant of a generic formal
+untagged type.
+@dby
+Operational and representation aspects of a generic formal parameter are the
+same as those of the actual. Operational and representation aspects are the
+same for all views of a type. A type-related representation item is not allowed
+for a descendant of a generic formal untagged type.
+
+!corrigendum J.11(1)
+
+@dinsc
+For the first subtype S of a type T declared by an
+@fa<incomplete_type_declaration> that is not tagged, the following attribute is
+defined:
+
+@xhang<@xterm<S'Class>Denotes the first subtype of the incomplete class-wide
+type rooted at T. The completion of T shall declare a tagged type. Such an
+attribute reference shall occur in the same library unit as the
+@fa<incomplete_type_declaration>.
 
 !ACATS Test
 

Questions? Ask the ACAA Technical Agent