------------------------
 
    procedure Check_Unused_Withs (Spec_Unit : Unit_Number_Type := No_Unit) is
-      Cnode : Node_Id;
-      Item  : Node_Id;
-      Lunit : Node_Id;
-      Ent   : Entity_Id;
 
       Munite : constant Entity_Id := Cunit_Entity (Main_Unit);
       --  This is needed for checking the special renaming case
       --------------------
 
       procedure Check_One_Unit (Unit : Unit_Number_Type) is
+         Cnode : constant Node_Id := Cunit (Unit);
+
          Is_Visible_Renaming : Boolean := False;
-         Pack                : Entity_Id;
 
          procedure Check_Inner_Package (Pack : Entity_Id);
          --  Pack is a package local to a unit in a with_clause. Both the unit
          --  referenced, then the only occurrence of Pack is in a USE clause
          --  or a pragma, and a warning is worthwhile as well.
 
-         function Check_System_Aux return Boolean;
+         function Check_System_Aux (Lunit : Entity_Id) return Boolean;
          --  Before giving a warning on a with_clause for System, check whether
          --  a system extension is present.
 
          -- Check_System_Aux --
          ----------------------
 
-         function Check_System_Aux return Boolean is
+         function Check_System_Aux (Lunit : Entity_Id) return Boolean is
             Ent : Entity_Id;
 
          begin
             return False;
          end Has_Visible_Entities;
 
+         --  Local variables
+
+         Ent   : Entity_Id;
+         Item  : Node_Id;
+         Lunit : Entity_Id;
+         Pack  : Entity_Id;
+
       --  Start of processing for Check_One_Unit
 
       begin
-         Cnode := Cunit (Unit);
-
          --  Only do check in units that are part of the extended main unit.
          --  This is actually a necessary restriction, because in the case of
          --  subprogram acting as its own specification, there can be with's in
                            if Unit = Spec_Unit then
                               Set_No_Entities_Ref_In_Spec (Item);
 
-                           elsif Check_System_Aux then
+                           elsif Check_System_Aux (Lunit) then
                               null;
 
                            --  Else the warning may be needed