This patch fixes a bug in the handling of use_type_clauses If a use_type_clause "use type X;" appears in the parent of a generic child package, and "use type X;" also appears before an instantiation of that generic child package, the second "use type X;" is ineffective; the primitive operators of type X are not directly visible where they should be.
The following test should compile quietly: package Utl is type Timerep_T is (Red); function "+" (Time : Timerep_T; Interval : Timerep_T) return Timerep_T; end Utl; with Utl; package Pfw is use type Utl.Timerep_T; end Pfw; generic package Pfw.Server is end Pfw.Server; with Pfw.Server; with Utl; package Beacon is use type Utl.Timerep_T; package Code_Server_Pkg is new Pfw.Server; One_Hour : Utl.Timerep_T; Two_hours : Utl.Timerep_T := One_Hour + One_Hour; end Beacon; Tested on x86_64-pc-linux-gnu, committed on trunk 2017-04-25 Bob Duff <d...@adacore.com> * sem_ch8.adb (Use_One_Type): If a use_type_clause is redundant, set its Used_Operations to empty. This is only necessary for use clauses that appear in the parent of a generic child unit, because those use clauses get reanalyzed when we instantiate the generic, and we don't want the Used_Operations carried over from the original context (where it was probably not redundant).
Index: sem_ch8.adb =================================================================== --- sem_ch8.adb (revision 247168) +++ sem_ch8.adb (working copy) @@ -9200,11 +9200,22 @@ ("incomplete type from limited view " & "cannot appear in use clause", Id); + -- If the use clause is redundant, Used_Operations will usually be + -- empty, but we need to set it to empty here in one case: If we are + -- instantiating a generic library unit, then we install the ancestors + -- of that unit in the scope stack, which involves reprocessing use + -- clauses in those ancestors. Such a use clause will typically have a + -- nonempty Used_Operations unless it was redundant in the generic unit, + -- even if it is redundant at the place of the instantiation. + + elsif Redundant_Use (Id) then + Set_Used_Operations (Parent (Id), New_Elmt_List); + -- If the subtype mark designates a subtype in a different package, -- we have to check that the parent type is visible, otherwise the -- use type clause is a noop. Not clear how to do that??? - elsif not Redundant_Use (Id) then + else Set_In_Use (T); -- If T is tagged, primitive operators on class-wide operands