This patch fixes a bug in which if a parent package has a use clause in
its private part, and a child of that parent has a use clause for the
same thing in its context clause, the compiler incorrectly warns that
the one in the child is redundant.
Tested on x86_64-pc-linux-gnu, committed on trunk
2019-12-18 Bob Duff <d...@adacore.com>
gcc/ada/
* sem_ch8.adb (Note_Redundant_Use): It was already checking for
a use clause in the visible part of the child. Add an additional
check for a use clause in the context clause of the child.
--- gcc/ada/sem_ch8.adb
+++ gcc/ada/sem_ch8.adb
@@ -9607,15 +9607,16 @@ package body Sem_Ch8 is
Par : constant Entity_Id := Defining_Entity (Parent (Decl));
Spec : constant Node_Id :=
Specification (Unit (Cunit (Current_Sem_Unit)));
-
+ Cur_List : constant List_Id := List_Containing (Cur_Use);
begin
if Is_Compilation_Unit (Par)
and then Par /= Cunit_Entity (Current_Sem_Unit)
- and then Parent (Cur_Use) = Spec
- and then List_Containing (Cur_Use) =
- Visible_Declarations (Spec)
then
- return;
+ if Cur_List = Context_Items (Cunit (Current_Sem_Unit))
+ or else Cur_List = Visible_Declarations (Spec)
+ then
+ return;
+ end if;
end if;
end;
end if;
@@ -9629,7 +9630,6 @@ package body Sem_Ch8 is
then
Redundant := Clause;
Prev_Use := Cur_Use;
-
end if;
if Present (Redundant) and then Parent (Redundant) /= Prev_Use then