6.5.1 Nonreturning Subprograms
Specifying aspect No_Return to have the value True
indicates that a subprogram cannot return normally; it may, for example,
propagate an exception or loop forever.
Static Semantics
For a subprogram (including
a generic formal subprogram), an access-to-subprogram type (including
a formal access-to-subprogram type), or a generic subprogram, the following
language-defined representation aspect may be specified:
No_Return
The type of aspect No_Return is Boolean. When aspect No_Return is True
for an entity, the entity is said to be
nonreturning.
If directly specified, the
aspect_definition
shall be a static expression. When not directly specified, if the subprogram
is a primitive subprogram inherited by a derived type, then the aspect
is True if any corresponding subprogram of the parent or progenitor types
is nonreturning. Otherwise, the aspect is False.
The No_Return aspect of a dereference of
a value of an access-to-subprogram type is the same as that of the type.
If a generic subprogram is nonreturning, then so
are its instances. If a subprogram declared within a generic unit is
nonreturning, then so are the corresponding copies of that subprogram
in instances.
Legality Rules
A subprogram defined by a
null_procedure_declaration
shall not be nonreturning. For an instance of a generic subprogram, any
specification of aspect No_Return shall be confirming.
A return statement shall not apply to a nonreturning
procedure or generic procedure.
An
extended_return_statement
shall not apply to a nonreturning function or generic function. Any return
expression of a nonreturning function or generic function shall be a
raise_expression,
a call on a nonreturning function, or a parenthesized expression of one
of these.
A subprogram shall be nonreturning if it overrides
a dispatching nonreturning subprogram.
In addition
to the places where Legality Rules normally apply (see
12.3),
this rule applies also in the private part of an instance of a generic
unit.
If a renaming-as-body completes a nonreturning subprogram
declaration, then the renamed subprogram shall be nonreturning.
If a No_Return aspect is True for a generic formal
subprogram or a generic formal access-to-subprogram type, it shall be
True for the matching actual in an instantiation.
If a No_Return aspect is True for an access-to-subprogram
type T, then it shall be True for a subprogram S if S'Access
has an expected type of T. Similarly, on a conversion to such
a type, the No_Return aspect shall be true for the operand type.
Paragraph 8 was deleted.
Dynamic Semantics
If the body of a nonreturning procedure completes
normally, Program_Error is raised at the point of the call.
Examples
Example of a specification
of a No_Return aspect:
procedure Fail(Msg : String) -- raises Fatal_Error exception
with No_Return;
-- Inform compiler and reader that procedure never returns normally
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe