Re: Question about circular elaboration order error (GNAT).



"Peter" == Peter C Chapin <pchapin@xxxxxxxxx> writes:

Peter> I don't understand where the circularity is coming from. Isn't
Peter> the following elaborate order acceptable:

No. pragma Elaborate_All is transitive, and forces the elaboration of
Parent body (since Parent.Child has an implicit dependency on Parent)
before... Parent body elaboration. Hence the circular elaboration
order.

But you can fix the situation by providing GNAT with the necessary
elaboration information:

- put a "pragma Elaborate (Parent.Child)" in Parent body to indicate
that Parent elaboration requires Parent.Child to be elaborated; this
pragma isn't transitive, so you have to ensure that subprograms of
Parent.Child called during the elaboration of Parent do not
themselves require that other packages be elaborated first, or add
the required pragma;

- put a "pragma Elaborate_Body" in Parent.Child spec if you know
that this package is likely to be called during the elaboration of
other packages; this requires that the body be elaborated just
after the spec.

Using only the "pragma Elaborate_Body" will not be enough for GNAT, so
the "pragma Elaborate" is required. That is because GNAT is
overcautious and adds implicit "pragma Elaborate_All" unless you
provide explicit "pragma Elaborate".

Note that having GNAT be overcautious by default is actually a good
thing: I spent three hours two weeks ago debugging a tricky
elaboration problem in a software written for an embedded system. The
original author incorrectly used "pragma Elaborate". Had he done
nothing, GNAT would have warned him about the dangerous situation.

I hope this clarifies things.

Sam
--
Samuel Tardieu -- sam@xxxxxxxxxxx -- http://www.rfc1149.net/
.



Relevant Pages

  • Re: Porting problems from Solaris to Redhat Linux using GNAT 5.01a on both.
    ... package that needed pragma Suppress to build. ... on a large infrastructure set using complex generics. ... I know you eventually indicated you used the correct compiler version and things worked but suppressing elaboration checks or general pragma suppresses being required to make something work is a very good indication that you have broken code that even if it appears to elaborate is probably not doing what you expect it to be doing. ...
    (comp.lang.ada)
  • Re: Question about library unit elaboration order.
    ... Clear if this is going to work right package Other's body needs to be ... "The order of elaboration of library units is determined primarily by ... elaboration dependency on package Other's body. ... unless you add an Elaborate or Elaborate_All pragma. ...
    (comp.lang.ada)
  • Re: Turning off "Unit xxx not referenced" warnings?
    ... > their elaboration. ... > there any way to get rid of them? ... Is there not a pragma or something for ... Implementation Defined Pragmas" of the GNAT Reference ...
    (comp.lang.ada)
  • Re: How did dynamic elaboration fix cyclic elaboration error???
    ... ada compile gnat switch -gnatE. ... Elaboration order problems can be very confusing and ... The static method does not conform to the Ada standard -- ... that the bind error will disappear, and you might or might not get ...
    (comp.lang.ada)
  • Re: New Ada portable GUI Library?
    ... I guess that even seasoned Ada programmers using GNAT don't wake up each ... with the various elaboration control pragmas. ... If you have code developed on a non-GNAT compiler, ...
    (comp.lang.ada)