ABE Diagnostics (GNAT User’s Guide for Native Platforms)

### 9.7 ABE Diagnostics ¶

GNAT performs extensive diagnostics on a unit-by-unit basis for all scenarios that invoke internal targets, regardless of whether the dynamic, SPARK, or static model is in effect.

Note that GNAT emits warnings rather than 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 invoked due to conditional execution. You can selectively suppress the warnings with `pragma Warnings (Off)` or globally with compiler switch `-gnatwL`.

A ‘guaranteed ABE’ arises when the body of a target is not elaborated early enough and causes ‘all’ scenarios that directly invoke 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 the following diagnostic:

>     4.    Val : constant Integer := ABE;
>                                     |
>        >>> warning: cannot call "ABE" before body seen
>        >>> warning: Program_Error will be raised at run time

A ‘conditional ABE’ arises when the body of a target is not elaborated early enough and causes ‘some’ scenarios that directly invoke the target to fail.

>      1. package body Conditional_ABE is
>      2.    procedure Force_Body is null;
>      3.
>      4.    generic
>      5.       with function Func return Integer;
>      6.    package Gen is
>      7.       Val : constant Integer := Func;
>      8.    end Gen;
>      9.
>     10.    function ABE return Integer;
>     11.
>     12.    function Cause_ABE return Boolean is
>     13.       package Inst is new Gen (ABE);
>     14.    begin
>     15.       ...
>     16.    end Cause_ABE;
>     17.
>     18.    Val : constant Boolean := Cause_ABE;
>     19.
>     20.    function ABE return Integer is
>     21.    begin
>     22.       ...
>     23.    end ABE;
>     24.
>     25.    Safe : constant Boolean := Cause_ABE;
>     26. end Conditional_ABE;

In the example above, the elaboration of package body `Conditional_ABE` elaborates the declaration of `Val`. This invokes function `Cause_ABE`, which instantiates generic unit `Gen` as `Inst`. The elaboration of `Inst` invokes function `ABE`, however the body of `ABE` has not been elaborated yet. GNAT emits the following diagnostic:

>     13.       package Inst is new Gen (ABE);
>               |
>         >>> warning: in instantiation at line 7
>         >>> warning: cannot call "ABE" before body seen
>         >>> warning: Program_Error may be raised at run time
>         >>> warning:   body of unit "Conditional_ABE" elaborated
>         >>> warning:   function "Cause_ABE" called at line 18
>         >>> warning:   function "ABE" called at line 7, instance at line 13

Note that the same ABE problem does not occur with the elaboration of declaration `Safe` because the body of function `ABE` has already been elaborated at that point.