This patch removes a spurious style warning on an operator declared in a
generic package when the package is used as a formal of a generic subprogram,
and the subprogream body includes a use clause on that package.
The following must compile quietly:
gcc -c -gnatyO generic_test.adb
---
with Generic_2;
procedure Generic_Test is
generic
with package P_1 is new Generic_2 (<>);
procedure S_1_G;
procedure S_1_G is
use P_1;
begin
null;
end S_1_G;
pragma Unreferenced (S_1_G);
begin
null;
end Generic_Test;
---
with Dummy;
pragma Unreferenced (Dummy);
with Generic_1;
generic
package Generic_2 is
package P_1 is new Generic_1 (T_1 => Natural);
end Generic_2;
---
generic
type T_1 is limited private;
package Generic_1 is
private
type T_2 is
record
X : T_1;
end record;
function "=" (Left, Right : T_2) return Boolean is (True);
end Generic_1;
--
package Dummy is
generic
type T is range <>;
package Dummy is
function Foo (Of_Image : String) return T renames T'Value;
end Dummy;
end Dummy;
Tested on x86_64-pc-linux-gnu, committed on trunk
2017-09-06 Ed Schonberg <[email protected]>
* sem_aux.adb (Is_Geeric_Formal): Handle properly formal packages.
* sem_ch3.adb (Analyze_Declarations): In a generic subprogram
body. do not freeze the formals of the generic unit.
Index: sem_ch3.adb
===================================================================
--- sem_ch3.adb (revision 251789)
+++ sem_ch3.adb (working copy)
@@ -2649,9 +2649,27 @@
-- in order to perform visibility checks on delayed aspects.
Adjust_Decl;
- Freeze_All (First_Entity (Current_Scope), Decl);
- Freeze_From := Last_Entity (Current_Scope);
+ -- If the current scope is a generic subprogram body. skip
+ -- the generic formal parameters that are not frozen here.
+
+ if Is_Subprogram (Current_Scope)
+ and then Nkind (Unit_Declaration_Node (Current_Scope))
+ = N_Generic_Subprogram_Declaration
+ and then Present (First_Entity (Current_Scope))
+ then
+ while Is_Generic_Formal (Freeze_From) loop
+ Freeze_From := Next_Entity (Freeze_From);
+ end loop;
+
+ Freeze_All (Freeze_From, Decl);
+ Freeze_From := Last_Entity (Current_Scope);
+
+ else
+ Freeze_All (First_Entity (Current_Scope), Decl);
+ Freeze_From := Last_Entity (Current_Scope);
+ end if;
+
-- Current scope is a package specification
elsif Scope (Current_Scope) /= Standard_Standard
Index: sem_aux.adb
===================================================================
--- sem_aux.adb (revision 251753)
+++ sem_aux.adb (working copy)
@@ -1053,9 +1053,13 @@
return
Nkind_In (Kind, N_Formal_Object_Declaration,
- N_Formal_Package_Declaration,
N_Formal_Type_Declaration)
- or else Is_Formal_Subprogram (E);
+ or else Is_Formal_Subprogram (E)
+
+ or else
+ (Ekind (E) = E_Package
+ and then Nkind (Original_Node (Unit_Declaration_Node (E))) =
+ N_Formal_Package_Declaration);
end if;
end Is_Generic_Formal;