AI22-0090-1

!standard 6.5.1(3.1/5)                                    24-04-16  AI22-0090-1/05

!standard 6.5.1(3.3/5)

!standard 6.5.1(7/5)

!class Amendment 23-12-07

!status Amendment 1-2022  23-12-14

!status WG9 Approved 24-06-10

!status ARG Approved  10-0-0  23-12-14

!status work item 23-12-07

!status received 23-12-07

!submitter Tucker Taft

!priority Low

!difficulty Easy

!subject No_Return for formal subprogram and access-to-subprogram types

!summary

We now allow a No_Return aspect to be specified on a formal subprogram of a generic unit and on an access-to-subprogram type (including a formal access-to-subprogram type).

!issue

The notion of a No_Return subprogram is useful when providing an operation to signal a fatal error of some sort, or to log an error and then raise an exception. If a client of an abstraction is going to provide such a subprogram as a parameter for a generic formal subprogram or for a formal parameter of an access-to-subprogram type, it would be useful to be able to require that the subprogram be a No_Return subprogram. Should we generalize the No_Return aspect so that it can apply to a formal subprogram and an access-to-subprogram type? (Yes.)

!recommendation

(See summary.)

!wording[a][b][c]

Modify 6.5.1(3.1/5):

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:

Add after 6.5.1(3.3/5):

The No_Return aspect of a dereference of a value of an access-to-subprogram type is the same as that of the type.

Add after 6.5.1(7/5):

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.

!discussion

As indicated in the !issue, it is useful to support the No_Return aspect on parameters of various sorts, including generic parameters and parameters of an access-to-subprogram type.  Here we have generalized it to access-to-subprogram types, generic formal subprograms, and generic formal access-to-subprogram types.

!example

Here is an example of defining an access-to-subprogram type that logs an error and then raises an exception. Complex_Operation expects the caller to provide a value of such a type so that it can be called if things go badly. Bad_News is a No_Return procedure which is passed in the example.

type Fatal_Error_Proc is access procedure (Msg : String)
  with No_Return;

procedure Bad_News (Reason : String)
  with No_Return;

procedure Complex_Operation (X : T; Fatal : Fatal_Error_Proc);

. . .

   Complex_Operation (Z, Bad_News'Access);

!corrigendum 6.5.1(3.1/5)

@drepl

For a subprogram or generic subprogram, the following language-defined representation aspect may be specified:

@dby

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:

!corrigendum 6.5.1(3.3/5)

@dinsa

@xindent{If directly specified, the @fa{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.}

@dinst

@xindent{The No_Return aspect of a dereference of a value of an access-to-subprogram type is the same as that of the type.}

!corrigendum 6.5.1(7/5)

@dinsa

If a renaming-as-body completes a nonreturning subprogram declaration, then the renamed subprogram shall be nonreturning.

@dinss

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 @i{T}, then it shall be True for a subprogram @i{S} if @i{S}'Access has an expected type of @i{T}. Similarly, on a conversion to such a type, the No_Return aspect shall be true for the operand type.

!ACATS test

An ACATS test should include something like the given example, as well as instantiations that exercise the rules on generic formals that have the aspect specified True.

!appendix

This is based on ARG GitHub issue #1.

[a]Change the pragma No_Return?

[b]Or perhaps leave as is in which case it would apply to formal subprograms but not access types.

[c]Consensus is to make no change to the wording about pragma No_Return, but it will now apply to generic formals.