Elaboration-related Compiler Switches (GNAT User’s Guide for Native Platforms)

### 9.11 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 model.

`-gnatel`

  Turn on informational messages on generated Elaborate[_All] pragmas

  This switch is only applicable to the pre-20.x legacy elaboration models. The post-20.x elaboration model no longer relies on implicitly generated `Elaborate` and `Elaborate_All` pragmas to order units.

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

  - ‘Dynamic model’

    GNAT will indicate missing `Elaborate` and `Elaborate_All` pragmas for all library-level scenarios within the partition.

  - ‘Static model’

    GNAT will indicate all scenarios invoked during elaboration. In addition, it will provide detailed traceback when an implicit `Elaborate` or `Elaborate_All` pragma is generated.

  - ‘SPARK model’

    GNAT will indicate how an elaboration requirement is met by the context of a unit. This diagnostic requires compiler switch `-gnatd.v`.

        1. with Server; pragma Elaborate_All (Server);
        2. package Client with SPARK_Mode is
        3.    Val : constant Integer := Server.Func;
                                              |
           >>> info: call to "Func" during elaboration in SPARK
           >>> info: "Elaborate_All" requirement for unit "Server" met by pragma at line 1

        4. end Client;

`-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.