6.5.1 Nonreturning ProceduresPragma No_Return
Discussion: Aspect Pragma No_Deposit will have to wait for Ada 2020 2017.
:-)
Syntax
Static Semantics
{
AI05-0229-1}
For a procedure or generic procedure, 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. [This aspect is never inherited;] if not
directly specified, the aspect is False.
Aspect Description
for No_Return: A
procedure will not return normally.
{
AI05-0229-1}
If a generic procedure is nonreturning, then so
are its instances. If a procedure declared within a generic unit is nonreturning,
then so are the corresponding copies of that procedure in instances.
Legality Rules
{
AI95-00329-01}
{
AI95-00414-01}
{
AI05-0229-1}
Aspect No_Return Each
procedure_local_name
shall denote one or more procedures or generic procedures; the denoted
entities are nonreturning. The procedure_local_name shall not be specified for denote a null procedure nor an instance of a generic unit.
Reason: A null
procedure cannot have the appropriate nonreturning semantics, as it does
not raise an exception or loop forever.
Ramification: {
AI05-0229-1}
The procedure can be abstract. The denoted declaration can be a renaming_declaration
if it obeys the usual rules for representation pragmas: the renaming
has to occur immediately within the same declarative region as the renamed
subprogram. If a nonreturning procedure
is renamed (anywhere) calls through the new name still have the nonreturning
semantics.
{
AI95-00414-01}
A procedure shall be nonreturning if it overrides
a dispatching nonreturning procedure. 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.
Reason: This ensures
that dispatching calls to nonreturning procedures will, in fact, not
return.
{
AI95-00414-01}
If a renaming-as-body completes a nonreturning
procedure declaration, then the renamed procedure shall be nonreturning.
Reason: This ensures
that no extra code is needed to implement the renames (that is, no wrapper
is needed) as the body has the same property.
Paragraph
8 was deleted.
Static Semantics
{
AI95-00329-01}
{
AI95-00414-01}
{
AI05-0229-1}
If
a generic procedure is nonreturning, then so are its instances. If a
procedure declared within a generic unit is nonreturning, then so are
the corresponding copies of that procedure in instances.
Dynamic Semantics
{
AI95-00329-01}
{
AI95-00414-01}
If the body of a nonreturning procedure completes
normally, Program_Error is raised at the point of the call.
Discussion: Note
that there is no name for suppressing this check, since the check represents
a bug, imposes no time overhead, and minimal space overhead (since it
can usually be statically eliminated as dead code).
Implementation Note:
If a nonreturning procedure tries to return, we raise Program_Error.
This is stated as happening at the call site, because we do not wish
to allow the procedure to handle the exception (and then, perhaps, try
to return again!). However, the expected run-time model is that the compiler
will generate raise Program_Error at the end of the procedure
body (but not handleable by the procedure itself), as opposed to doing
it at the call site. (This is just like the typical run-time model for
functions that fall off the end without returning a value). The reason
is indirect calls: in P.all(...);, the compiler cannot know whether
P designates a nonreturning procedure or a normal one. Putting the raise
Program_Error in the procedure's generated code solves this problem neatly.
Similarly, if one passes
a nonreturning procedure to a generic formal parameter, the compiler
cannot know this at call sites (in shared code implementations); the
raise-in-body solution deals with this neatly.
Examples
{
AI95-00433-01}
{
AI05-0229-1}
procedure Fail(Msg : String); -- raises Fatal_Error exception
with pragma No_Return(Fail);
-- Inform compiler and reader that procedure never returns normally
Extensions to Ada 95
Extensions to Ada 2005
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe