Annotated Ada Reference ManualLegal Information
Table of Contents   Index   References   Search   Previous   Next 

 6.5.1 Pragma No_Return

1/2
{AI95-00329-01} {AI95-00414-01} A pragma No_Return indicates that a procedure cannot return normally[; it may propagate an exception or loop forever]. 
1.a/2
Discussion: Pragma No_Deposit will have to wait for Ada 2017. :-) 

Syntax

2/2
{AI95-00329-01} {AI95-00414-01} The form of a pragma No_Return, which is a representation pragma (see 13.1), is as follows: 
3/2
  pragma No_Return(procedure_local_name{, procedure_local_name});

Legality Rules

4/2
{AI95-00329-01} {AI95-00414-01} {non-returning} Each procedure_local_name shall denote one or more procedures or generic procedures; the denoted entities are non-returning. The procedure_local_name shall not denote a null procedure nor an instance of a generic unit.
4.a/2
Reason: A null procedure cannot have the appropriate non-returning semantics, as it does not raise an exception or loop forever. 
4.b/2
Ramification: 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 non-returning procedure is renamed (anywhere) calls through the new name still have the non-returning semantics.
5/2
{AI95-00329-01} {AI95-00414-01} A return statement shall not apply to a non-returning procedure or generic procedure.
6/2
{AI95-00414-01} A procedure shall be non-returning if it overrides a dispatching non-returning procedure. {generic contract issue [partial]} 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.
6.a/2
Reason: This ensures that dispatching calls to non-returning procedures will, in fact, not return. 
7/2
{AI95-00414-01} If a renaming-as-body completes a non-returning procedure declaration, then the renamed procedure shall be non-returning.
7.a/2
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. 

Static Semantics

8/2
{AI95-00329-01} {AI95-00414-01} If a generic procedure is non-returning, then so are its instances. If a procedure declared within a generic unit is non-returning, then so are the corresponding copies of that procedure in instances.

Dynamic Semantics

9/2
{AI95-00329-01} {AI95-00414-01} If the body of a non-returning procedure completes normally, Program_Error is raised at the point of the call. {Program_Error (raised by failure of run-time check)}
9.a/2
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). 
9.b/2
Implementation Note: If a non-returning 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 non-returning procedure or a normal one. Putting the raise Program_Error in the procedure's generated code solves this problem neatly.
9.c/2
Similarly, if one passes a non-returning 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

10/2
{AI95-00433-01} procedure Fail(Msg : String);  -- raises Fatal_Error exception
pragma No_Return(Fail);
   -- Inform compiler and reader that procedure never returns normally

Extensions to Ada 95

10.a/2
{AI95-00329-01} {AI95-00414-01} {extensions to Ada 95} Pragma No_Return is new. 

Table of Contents   Index   References   Search   Previous   Next 
Ada-Europe Sponsored by Ada-Europe