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

9.7 Treatment of Pragma Elaborate

The use of pragma Elaborate should generally be avoided in Ada 95 and Ada 2005 programs, since there is no guarantee that transitive calls will be properly handled. Indeed at one point, this pragma was placed in Annex J (Obsolescent Features), on the grounds that it is never useful.

Now that’s a bit restrictive. In practice, the case in which pragma Elaborate is useful is when the caller knows that there are no transitive calls, or that the called unit contains all necessary transitive pragma Elaborate statements, and legacy code often contains such uses.

Strictly speaking the static mode in GNAT should ignore such pragmas, since there is no assurance at compile time that the necessary safety conditions are met. In practice, this would cause GNAT to be incompatible with correctly written Ada 83 code that had all necessary pragma Elaborate statements in place. Consequently, we made the decision that GNAT in its default mode will believe that if it encounters a pragma Elaborate then the programmer knows what they are doing, and it will trust that no elaboration errors can occur.

The result of this decision is two-fold. First to be safe using the static mode, you should remove all pragma Elaborate statements. Second, when fixing circularities in existing code, you can selectively use pragma Elaborate statements to convince the static mode of GNAT that it need not generate an implicit pragma Elaborate_All statement.

When using the static mode with `-gnatwl', any use of pragma Elaborate will generate a warning about possible problems.

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