12.5.4 Formal Access Types
[The category determined for a formal access type is the category of
all access types.]
This rule follows from the rule in 12.5
says that the category is determined by the one given in the name of
the syntax production. The effect of the rule is repeated here to give
a capsule summary of what this subclause is about.
For a formal access-to-object type, the designated
subtypes of the formal and actual types shall statically match.
If and only if the general_access_modifier
applies to the formal, the actual shall be an access-to-constant
type. If the general_access_modifier
applies to the formal, then the actual shall be a general
access-to-variable type (see 3.10
). If and
only if the formal subtype excludes null, the actual subtype shall exclude
Ramification: If no _modifier
applies to the formal, then the actual type may be either a pool-specific
or a general access-to-variable type.
Matching an access-to-variable to a formal access-to-constant type cannot
be allowed. If it were allowed, it would be possible to create an access-to-variable
value designating a constant.
We require that the “excludes null” property match, because
it would be difficult to write a correct generic for a formal access
type without knowing this property. Many typical algorithms and techniques
will not work for a subtype that excludes null (setting an unused component
, default-initialized objects, and so on). Even Ada.Unchecked_Deallocation
would fail for a subtype that excludes null. Most generics would end
up with comments saying that they are not intended to work for subtypes
that exclude null. We would rather that this sort of requirement be reflected
in the contract of the generic.
For a formal access-to-subprogram subtype, the designated profiles of
the formal and the actual shall be subtype conformant.
Example of formal
-- the formal types of the generic package
type Node is private;
type Link is access Node;
package P is
-- can be matched by the actual types
type Car_Name is access Car;
type Car is
Pred, Succ : Car_Name;
Number : License_Number;
Owner : Person;
-- in the following generic instantiation
package R is new P(Node => Car, Link => Car_Name);
Incompatibilities With Ada 83
The check for matching of
designated subtypes is changed from a run-time check to a compile-time
check. The Ada 83 rule that “If the designated type is other than
a scalar type, then the designated subtypes shall be either both constrained
or both unconstrained” is removed, since it is subsumed by static
Extensions to Ada 83
subtypes and formal general access types are new concepts.
Wording Changes from Ada 95
Added a matching rule for subtypes that exclude null.
We change to “determines a category” as that is the new terminology
(it avoids confusion, since not all interesting properties form a class).
Incompatibilities With Ada 2005
Matching of formal access-to-subprogram
types now uses subtype conformance rather than mode conformance, which
is needed to plug a hole. This could cause some instantiations legal
in Ada 95 and Ada 2005 to be rejected in Ada 2012. We believe that formal
access-to-subprogram types occur rarely, and actuals that are not subtype
conformant are rarer still, so this should not happen often. (In addition,
one popular compiler has a bug that causes such instances to be rejected,
so no code compiled with that compiler could have an incompatibility.)
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe