Next: Dynamic Elaboration Model in GNAT, Previous: Controlling the Elaboration Order in GNAT, Up: Elaboration Order Handling in GNAT [Contents][Index]
All three GNAT models are able to detect elaboration problems related to dispatching calls and a particular kind of ABE referred to as `guaranteed ABE'.
GNAT installs run-time checks for each primitive subprogram of each tagged
type defined in a partition on the assumption that a dispatching call
invoked at elaboration time will execute one of these primitives. As a
result, a dispatching call that executes a primitive whose body has not
been elaborated yet will raise exception Program_Error at run time. The
checks can be suppressed using pragma Suppress (Elaboration_Check).
A guaranteed ABE arises when the body of a target is not elaborated early enough, and causes all scenarios that directly execute the target to fail.
package body Guaranteed_ABE is
function ABE return Integer;
Val : constant Integer := ABE;
function ABE return Integer is
begin
...
end ABE;
end Guaranteed_ABE;
In the example above, the elaboration of Guaranteed_ABE’s body elaborates
the declaration of Val. This invokes function ABE, however the body
of ABE has not been elaborated yet. GNAT emits similar diagnostics in all
three models:
1. package body Guaranteed_ABE is
2. function ABE return Integer;
3.
4. Val : constant Integer := ABE;
|
>>> warning: cannot call "ABE" before body seen
>>> warning: Program_Error will be raised at run time
5.
6. function ABE return Integer is
7. begin
8. ...
9. end ABE;
10. end Guaranteed_ABE;
Note that GNAT emits warnings rather than hard errors whenever it encounters an
elaboration problem. This is because the elaboration model in effect may be too
conservative, or a particular scenario may not be elaborated or executed due to
data and control flow. The warnings can be suppressed selectively with pragma
Warnigns (Off) or globally with compiler switch -gnatwL.