This patch removes a spurious elaboration warning on some calls to
postconditions. Such a call always appears within an enclosing body, and as
such is not subject to an elaboration check, but the call that is inserted
after the final (inserted) return statement in a procedure body is analyzed
in the enclosing context, which may be a compilation unit. Such a call is
now properly handled.

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-08-04  Ed Schonberg  <schonb...@adacore.com>

        * sem_elab.adb (Check_Elab_Call): Do not check a call to a
        postcondtion.
        * exp_ch6.adb (Expand_Call): Clarify handling of inserted
        postcondition call.

Index: sem_elab.adb
===================================================================
--- sem_elab.adb        (revision 213536)
+++ sem_elab.adb        (working copy)
@@ -1218,6 +1218,17 @@
          return;
       end if;
 
+      --  Nothing to do if this is a call to a postcondition, which is always
+      --  within a subprogram body, even though the current scope may be the
+      --  enclosing scope of the subprogram.
+
+      if Nkind (N) = N_Procedure_Call_Statement
+        and then Is_Entity_Name (Name (N))
+        and then Chars (Entity (Name (N))) = Name_uPostconditions
+      then
+         return;
+      end if;
+
       --  Here we have a call at elaboration time which must be checked
 
       if Debug_Flag_LL then
Index: exp_ch6.adb
===================================================================
--- exp_ch6.adb (revision 213567)
+++ exp_ch6.adb (working copy)
@@ -5209,6 +5209,13 @@
                --  Analyze call, but something goes wrong in some weird cases
                --  and it is not worth worrying about ???
 
+               --  The return statement is handled properly, and the call to
+               --  the postcondition, inserted below, does not require
+               --  information from the body either. However, that call is
+               --  analyzed in the enclosing scope, and an elaboration check
+               --  might improperly be added to it.  A guard in sem_elab is
+               --  needed to prevent that spurious check, see Check_Elab_Call.
+
                Append_To (S, Rtn);
                Set_Analyzed (Rtn);
 

Reply via email to