Contents Index Previous Next
13.9.2 The Valid Attribute
1
The Valid attribute can be used to check the validity
of data produced by unchecked conversion, input, interface to foreign
languages, and the like.
Static Semantics
2
For a prefix
X that denotes a scalar object [(after any implicit dereference)], the
following attribute is defined:
3
- X'Valid
-
Yields True if and only if the
object denoted by X is normal and has a valid representation. The value
of this attribute is of the predefined type Boolean.
3.a
Ramification: Having checked
that X'Valid is True, it is safe to read the value of X without fear
of erroneous execution caused by abnormality, or a bounded error caused
by an invalid representation. Such a read will produce a value in the
subtype of X.
4
19 Invalid
data can be created in the following cases (not counting erroneous or
unpredictable execution):
5
- an uninitialized scalar object,
6
- the result of an unchecked conversion,
7
8
- interface to another language (including machine code),
9
10
- disrupting an assignment due to the failure of a language-defined
check (see 11.6), and
11
- use of an object whose Address has been specified.
12
20 X'Valid is not considered
to be a read of X; hence, it is not an error to check the validity of
invalid data.
12.a
Ramification: If X is of
an enumeration type with a representation clause, then X'Valid checks
that the value of X when viewed as an integer is one of the specified
internal codes.
12.b
Reason: Valid is defined
only for scalar objects because the implementation and description burden
would be too high for other types. For example, given a typical run-time
model, it is impossible to check the validity of an access value. The
same applies to composite types implemented with internal pointers. One
can check the validity of a composite object by checking the validity
of each of its scalar subcomponents. The user should ensure that any
composite types that need to be checked for validity are represented
in a way that does not involve implementation-defined components, or
gaps between components. Furthermore, such types should not contain access
subcomponents.
12.c
Note that one can safely check the validity
of a composite object with an abnormal value only if the constraints on the
object and all of its subcomponents are static. Otherwise, evaluation of the
prefix of the attribute_reference
causes erroneous execution (see 4.1).
Extensions to Ada 83
12.d
{extensions to Ada 83}
X'Valid is new in Ada 95.
Contents Index Previous Next Legal