7.5 Limited Types
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
[A limited type is (a view of) a type for which copying (such as for an
assignment_statement) is not allowed. A nonlimited type is a (view of a) type for which copying is allowed.]
assignment_statement) is not allowed. A nonlimited type is a type for which copying is allowed.
If a tagged record type has any limited components, then the reserved word limited shall appear in its
record_type_definition. [If the reserved word limited appears in the definition of a
derived_type_definition, its parent type and any progenitor interfaces shall be limited.]
package P is type T is limited private; type R is tagged record -- Illegal! -- This should say “limited record”. X : T; end record; private type T is new Integer; -- R becomes nonlimited here. end P; 3.c/2package Q is type R2 is new R with record Y : Some_Task_Type; end record; end Q;
In the following contexts, an
expression of a limited type is permitted only if each of its operative constituents is newly constructed (see 4.4) :
- the initialization
object_declaration(see 3.3.1) 3.3/2
component_declaration(see 3.8) 3.4/2
record_component_association(see 4.3.1) 3.5/2
extension_aggregate(see 4.3.2) 3.6/2
array_component_association(see 4.3.3) 3.7/5
- the base_
array_delta_aggregatehere, as its type cannot be limited (see 4.3.4), and thus neither can its base_
expression. Similarly, we do not need any rules for components of a
delta_aggregatenor the elements of a
container_aggregate, as neither are allowed to be limited (see 4.3.4 and 4.3.5)
qualified_expressionof an initialized allocator (see 4.8) 3.9/5
expressionof a return statement (see 6.5) 3.10/5
- the return expression of an expression function (see 6.8)
default_expressionor actual parameter for a formal object of mode in (see 12.4)
A view of a type is limited if it is one of the following:
- a type with the reserved word limited, synchronized, task, or protected in its definition;
- a class-wide type whose specific type is limited;
- a composite type with a limited component;
- an incomplete view;
- a derived type whose parent is limited and is not an interface.
Otherwise, the type is nonlimited.
[There are no predefined equality operators for a limited type.]
A type is immutably limited if it is one of the following:
- An explicitly limited record type;
- A record extension with the reserved word limited;
- A nonformal limited private type that is tagged or has at least one access discriminant with a
- A task type, a protected type, or a synchronized interface;
- A type derived from an immutably limited type.
A descendant of a generic formal limited private type is presumed to be immutably limited except within the body of a generic unit or a body declared within the declarative region of a generic unit, if the formal type is declared within the formal part of the generic unit.
function_call, and such
function_calls will be built directly in the target object (see 7.6).
function_calls only are required to be build-in-place for “really” limited types.
Example of a package with a limited type:
package IO_Package is type File_Name is limited private; 20procedure Open (F : in out File_Name); procedure Close(F : in out File_Name); procedure Read (F : in File_Name; Item : out Integer); procedure Write(F : in File_Name; Item : in Integer); private type File_Name is limited record Internal_Name : Integer := 0; end record; end IO_Package; 21package body IO_Package is Limit : constant := 200; type File_Descriptor is record ... end record; Directory : array (1 .. Limit) of File_Descriptor; ... procedure Open (F : in out File_Name) is ... end; procedure Close(F : in out File_Name) is ... end; procedure Read (F : in File_Name; Item : out Integer) is ... end; procedure Write(F : in File_Name; Item : in Integer) is ... end; begin ... end IO_Package;
Extensions to Ada 83
Wording Changes from Ada 83
Extensions to Ada 95
Aggregates were not allowed to have a limited type in Ada 95, which causes a compatibility issue discussed in 4.3, “Aggregates”. Compatibility issues with return statements for limited
function_calls are discussed in 6.5, “Return Statements”.
Wording Changes from Ada 95
Wording Changes from Ada 2005
conditional_expressions in limited constructor contexts — we want to treat these as closely to parentheses as possible.
Extensions to Ada 2012
raise_expressioncan be used in an expression used in a limited context. This is harmless (no object will be created if an exception is raised instead), useful, and thus appears to have been an omission when
raise_expressions were added to the language.
Wording Changes from Ada 2012
delta_aggregateas a limited context.