This patch updates the legality checks of aspect/pragma Global to allow references to enclosing formal parameters.
------------ -- Source -- ------------ -- formal_references.adb procedure Formal_References (In_Formal : Integer; In_Out_Formal : in out Integer; Out_Formal : out Integer) is procedure Nested (Own_Formal : Integer) with Global => (Input => (In_Formal, Own_Formal), In_Out => In_Out_Formal, Output => Out_Formal), Depends => (Out_Formal => (In_Formal, In_Out_Formal, Own_Formal), In_Out_Formal => In_Out_Formal) is begin null; end Nested; begin null; end Formal_References; ---------------------------- -- Compilation and output -- ---------------------------- $gcc -c -gnat12 -gnatd.V formal_references.adb formal_references.adb:7:44: global item cannot reference formal parameter Tested on x86_64-pc-linux-gnu, committed on trunk 2013-10-14 Hristian Kirtchev <kirtc...@adacore.com> * sem_prag.adb (Analyze_Global_Item): Allow references to enclosing formal parameters.
Index: sem_prag.adb =================================================================== --- sem_prag.adb (revision 203522) +++ sem_prag.adb (working copy) @@ -1428,13 +1428,16 @@ if Present (Item_Id) then - -- A global item cannot reference a formal parameter. Do this - -- check first to provide a better error diagnostic. + -- A global item may denote a formal parameter of an enclosing + -- subprogram. Do this check first to provide a better error + -- diagnostic. if Is_Formal (Item_Id) then - Error_Msg_N - ("global item cannot reference formal parameter", Item); - return; + if Scope (Item_Id) = Subp_Id then + Error_Msg_N + ("global item cannot reference formal parameter", Item); + return; + end if; -- The only legal references are those to abstract states and -- variables.