this patch updates the analysis of package body stubs and subprogram body stubs
to maintain the configuration options of the enclosing context in a stack-like
fasion. This ensures that options pertaining to the proper body do not govern
the options of the enclosing context.

------------
-- Source --
------------

--  pack.ads

package Pack is
   procedure Must_Fail;
end Pack;

--  pack.adb

package body Pack is
   pragma Assertion_Policy (Assert => Check);

   package Pack_Stub is
      procedure Pack_Stub_Proc;
   end Pack_Stub;

   package body Pack_Stub is separate;

   procedure Proc_Stub;
   procedure Proc_Stub is separate;

   procedure Must_Fail is
   begin
      pragma Assert (False);
      null;
   end Must_Fail;
end Pack;

--  pack-pack_stub.adb

separate (Pack)

package body Pack_Stub is
   procedure Pack_Stub_Proc is begin null; end Pack_Stub_Proc;
end Pack_Stub;

--  pack-proc_stub.adb

separate (Pack)

procedure Proc_Stub is begin null; end Proc_Stub;

--  config_opts.adb

with Pack; use Pack;

procedure Config_Opts is
begin
   Must_Fail;
end Config_Opts;

----------------------------
-- Compilation and output --
----------------------------

$ gnatmake -q config_opts.adb
$ ./config_opts
raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : pack.adb:15

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

2014-02-06  Hristian Kirtchev  <kirtc...@adacore.com>

        * sem_ch10.adb (Analyze_Package_Body_Stub): Maintain
        the configuration options of the enclosing context in a
        stack-like fasion.
        (Analyze_Subprogram_Body_Stub): Maintain the
        configuration options of the enclosing context in a stack-like
        fashion.

Index: sem_ch10.adb
===================================================================
--- sem_ch10.adb        (revision 207533)
+++ sem_ch10.adb        (working copy)
@@ -1513,8 +1513,9 @@
    -------------------------------
 
    procedure Analyze_Package_Body_Stub (N : Node_Id) is
-      Id  : constant Entity_Id := Defining_Identifier (N);
-      Nam : Entity_Id;
+      Id   : constant Entity_Id := Defining_Identifier (N);
+      Nam  : Entity_Id;
+      Opts : Config_Switches_Type;
 
    begin
       --  The package declaration must be in the current declarative part
@@ -1531,6 +1532,11 @@
          Error_Msg_N ("duplicate or redundant stub for package", N);
 
       else
+         --  Retain and restore the configuration options of the enclosing
+         --  context as the proper body may introduce a set of its own.
+
+         Save_Opt_Config_Switches (Opts);
+
          --  Indicate that the body of the package exists. If we are doing
          --  only semantic analysis, the stub stands for the body. If we are
          --  generating code, the existence of the body will be confirmed
@@ -1541,6 +1547,8 @@
          Set_Corresponding_Spec_Of_Stub (N, Nam);
          Generate_Reference (Nam, Id, 'b');
          Analyze_Proper_Body (N, Nam);
+
+         Restore_Opt_Config_Switches (Opts);
       end if;
    end Analyze_Package_Body_Stub;
 
@@ -1913,6 +1921,7 @@
 
    procedure Analyze_Subprogram_Body_Stub (N : Node_Id) is
       Decl : Node_Id;
+      Opts : Config_Switches_Type;
 
    begin
       Check_Stub_Level (N);
@@ -1937,11 +1946,18 @@
          end loop;
       end if;
 
+      --  Retain and restore the configuration options of the enclosing context
+      --  as the proper body may introduce a set of its own.
+
+      Save_Opt_Config_Switches (Opts);
+
       --  Treat stub as a body, which checks conformance if there is a previous
       --  declaration, or else introduces entity and its signature.
 
       Analyze_Subprogram_Body (N);
       Analyze_Proper_Body (N, Empty);
+
+      Restore_Opt_Config_Switches (Opts);
    end Analyze_Subprogram_Body_Stub;
 
    ---------------------

Reply via email to