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.Legality Rules
3/2If 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
expression
of anobject_declaration
(see 3.3.1) 3.3/2 - the
default_expression
of acomponent_declaration
(see 3.8) 3.4/2 - the
expression
of arecord_component_association
(see 4.3.1) 3.5/2 - the
expression
for anancestor_part
of anextension_aggregate
(see 4.3.2) 3.6/2 - an
expression
of apositional_array_aggregate
or theexpression
of anarray_component_association
(see 4.3.3) 3.7/5 - the base_
expression
of arecord_delta_aggregate
(see 4.3.4)
expression
of an array_delta_aggregate
here, 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_aggregate
nor the elements of a container_aggregate
, as neither are allowed to be limited (see 4.3.4 and 4.3.5) - the
qualified_expression
of an initialized allocator (see 4.8) 3.9/5 - the
expression
of a return statement (see 6.5) 3.10/5 - the return expression of an expression function (see 6.8)
- the
default_expression
or actual parameter for a formal object of mode in (see 12.4)
Static Semantics
4/3A 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
default_expression
;
- 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.
aggregate
or function_call
, and such aggregate
s and function_call
s will be built directly in the target object (see 7.6). function_call
s only are required to be build-in-place for “really” limited types. Examples
18Example 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
aggregate
s and function_call
s. Aggregate
s 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_call
s are discussed in 6.5, “Return Statements”. Wording Changes from Ada 95
Wording Changes from Ada 2005
conditional_expression
s in limited constructor contexts — we want to treat these as closely to parentheses as possible.Extensions to Ada 2012
raise_expression
can 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_expression
s were added to the language.