Ada Programming/Aspects/No Return

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Ada. Time-tested, safe and secure.
Ada. Time-tested, safe and secure.
with No_Return

Description[edit | edit source]

Specifying the aspect No_Return indicates that a procedure cannot return normally; it may raise an exception, loop forever, or terminate the program.

A non-returning procedure may not contain any return statements. If a non-returning procedure implicitly returns (by reaching the end of its statement sequence), Program_Error will be raised at the point of call.

On the call site, this enables detection of dead code and suppression of warnings about missing return statements or missing assignment to variables.

Example[edit | edit source]

procedure P ( … ) with No_Return;
procedure Q (x : out … ) is
  if Cond then
    P ( … );
    Some_Thing_Else; -- This is dead code--and due to No_Return probably a compiler warning!
    x := … ;
  end if;
  -- No warning about a missing assignment to x here
end Q;

Portability[edit | edit source]

The aspect No_Return was introduced in Ada 2012. It is the replacement[1] for pragma No_Return which was introduced in Ada 2005.[2]

See also[edit | edit source]

Wikibook[edit | edit source]

Ada Reference Manual[edit | edit source]

References[edit | edit source]

  1. AI05-0229
  2. AI95-00329