Next: , Previous: , Up: Elaboration Order Handling in GNAT   [Contents][Index]


9.15 Elaboration-related Compiler Switches

GNAT has several switches that affect the elaboration model and consequently the elaboration order chosen by the binder.

-gnatE

Dynamic elaboration checking mode enabled

When this switch is in effect, GNAT activates the dynamic elaboration model.

-gnatel

Turn on info messages on generated Elaborate[_All] pragmas

When this switch is in effect, GNAT will emit the following supplementary information depending on the elaboration model in effect.

-gnatH

Legacy elaboration checking mode enabled

When this switch is in effect, GNAT will utilize the pre-18.x elaboration model.

-gnatJ

Relaxed elaboration checking mode enabled

When this switch is in effect, GNAT will not process certain scenarios, resulting in a more permissive elaboration model. Note that this may eliminate some diagnostics and run-time checks.

-gnatw.f

Turn on warnings for suspicious Subp’Access

When this switch is in effect, GNAT will treat 'Access of an entry, operator, or subprogram as a potential call to the target and issue warnings:

 1. package body Attribute_Call is
 2.    function Func return Integer;
 3.    type Func_Ptr is access function return Integer;
 4.
 5.    Ptr : constant Func_Ptr := Func'Access;
                                      |
    >>> warning: "Access" attribute of "Func" before body seen
    >>> warning: possible Program_Error on later references
    >>> warning:   body of unit "Attribute_Call" elaborated
    >>> warning:   "Access" of "Func" taken at line 5

 6.
 7.    function Func return Integer is
 8.    begin
 9.       ...
10.    end Func;
11. end Attribute_Call;

In the example above, the elaboration of declaration Ptr is assigned Func'Access before the body of Func has been elaborated.

-gnatwl

Turn on warnings for elaboration problems

When this switch is in effect, GNAT emits diagnostics in the form of warnings concerning various elaboration problems. The warnings are enabled by default. The switch is provided in case all warnings are suppressed, but elaboration warnings are still desired.

-gnatwL

Turn off warnings for elaboration problems

When this switch is in effect, GNAT no longer emits any diagnostics in the form of warnings. Selective suppression of elaboration problems is possible using pragma Warnings (Off).

 1. package body Selective_Suppression is
 2.    function ABE return Integer;
 3.
 4.    Val_1 : constant Integer := ABE;
                                   |
    >>> warning: cannot call "ABE" before body seen
    >>> warning: Program_Error will be raised at run time

 5.
 6.    pragma Warnings (Off);
 7.    Val_2 : constant Integer := ABE;
 8.    pragma Warnings (On);
 9.
10.    function ABE return Integer is
11.    begin
12.       ...
13.    end ABE;
14. end Selective_Suppression;

Note that suppressing elaboration warnings does not eliminate run-time checks. The example above will still fail at run time with an ABE.


Next: , Previous: , Up: Elaboration Order Handling in GNAT   [Contents][Index]