C.8. Elaboration for Access-to-Subprogram Values

The introduction of access-to-subprogram types in Ada 95 complicates the handling of elaboration. The trouble is that we now have a situation where it is impossible at compile time to tell exactly which procedure is being called. This means that it is not possible to analyze the elaboration requirements statically at compile time in this case.

If at the time the access value is created, the body of the subprogram is known to have been elaborated, then the access value is safe, and its use does not require a check. This may be achieved by appropriate arrangement of the order of declarations if the subprogram is in the current unit, or, if the subprogram is in another unit, then by using pragma Pure, Preelaborate, or Elaborate_Body on the referenced unit.

If the referenced body is not known to have been elaborated at the time the access value is created, then any use of the access value must do a dynamic check, and this dynamic check will fail, raising a Program_Error exception if the body still has not been elaborated. XGC Ada will generate the necessary checks, and in addition, if the -gnatwl switch is set, will generate warnings that such checks are required.

The use of dynamic dispatching for tagged types similarly generates a requirement for dynamic checks, and premature calls to any primitive operation of a tagged type, before the body has been elaborated, will also result in the raising of a Program_Error exception