13.9.1 Data Validity
Certain actions that can potentially lead to erroneous
execution are not directly erroneous, but instead can cause objects to
become abnormal. Subsequent uses of abnormal objects can be erroneous.
A scalar object can have an
invalid representation,
which means that the object's representation does not represent any value
of the object's subtype.
The primary cause of invalid
representations is uninitialized variables.
Abnormal objects and invalid representations are
explained in this subclause.
Dynamic Semantics
When
an object is first created, and any explicit or default initializations
have been performed, the object and all of its parts are in the
normal
state. Subsequent operations generally leave them normal. However, an
object or part of an object can become
abnormal in the following
ways:
An assignment to the object
is disrupted due to an abort (see
9.8) or due
to the failure of a language-defined check (see
11.6).
The object is not scalar, and is passed to an in
out or out parameter of an imported procedure, the Read procedure
of an instance of Sequential_IO, Direct_IO, or Storage_IO, or the stream
attribute T'Read, if after return from the procedure the representation
of the parameter does not represent a value of the parameter's subtype.
The object is the return object of a function call
of a nonscalar type, and the function is an imported function, an instance
of Unchecked_Conversion, or the stream attribute T'Input, if after return
from the function the representation of the return object does not represent
a value of the function's subtype.
For an imported object, it is the programmer's responsibility
to ensure that the object remains in a normal state.
Whether or not an object actually
becomes abnormal in these cases is not specified. An abnormal object
becomes normal again upon successful completion of an assignment to the
object as a whole.
Erroneous Execution
It is erroneous to evaluate a
primary that
is a
name
denoting an abnormal object, or to evaluate a
prefix
that denotes an abnormal object.
Bounded (Run-Time) Errors
If
the representation of a scalar object does not represent a value of the
object's subtype (perhaps because the object was not initialized), the
object is said to have an
invalid representation. It is a bounded
error to evaluate the value of such an object. If the error is detected,
either Constraint_Error or Program_Error is raised.
Otherwise, execution continues using the invalid
representation. The rules of the language outside this subclause assume
that all objects have valid representations. The semantics of operations
on invalid representations are as follows:
If the representation of the object represents
a value of the object's type, the value of the type is used.
If the representation of the object does not represent
a value of the object's type, the semantics of operations on such representations
is implementation-defined, but does not by itself lead to erroneous or
unpredictable execution, or to other objects becoming abnormal.
Erroneous Execution
A call to an imported function
or an instance of Unchecked_Conversion is erroneous if the result is
scalar, the result object has an invalid representation, and the result
is used other than as the
expression
of an
assignment_statement
or an
object_declaration,
as the
object_name
of an
object_renaming_declaration,
or as the
prefix
of a Valid attribute. If such a result object is used as the source of
an assignment, and the assigned value is an invalid representation for
the target of the assignment, then any use of the target object prior
to a further assignment to the target object, other than as the
prefix
of a Valid attribute reference, is erroneous.
The dereference of an access
value is erroneous if it does not designate an object of an appropriate
type or a subprogram with an appropriate profile, if it designates a
nonexistent object, or if it is an access-to-variable value that designates
a constant object and it did not originate from an attribute_reference
applied to an aliased variable view of a controlled or immutably limited
object. An access value whose dereference is erroneous can exist, for
example, because of Unchecked_Deallocation, Unchecked_Access, or Unchecked_Conversion.
NOTE Objects can become abnormal
due to other kinds of actions that directly update the object's representation;
such actions are generally considered directly erroneous, however.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe