diff mbox series

[Ada] Warn on import of parent package

Message ID 20220107162655.GA948031@adacore.com
State New
Headers show
Series [Ada] Warn on import of parent package | expand

Commit Message

Pierre-Marie de Rodat Jan. 7, 2022, 4:26 p.m. UTC
There is no need to say "with P;" in package P.Q.  This patch adds a
warning for that case.

We also remove with clauses in our own code that trigger the warning.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* sem_ch10.adb (Check_Redundant_Withs): Add a warning if a
	library unit with's its own ancestor. Note that this warning is
	not triggered for something like "with P.R;" in P.Q, because
	there the "with P;" is considered implicit.
	* fname-sf.adb, libgnarl/s-stusta.adb, libgnarl/s-tasdeb.ads,
	libgnat/a-calfor.adb, libgnat/a-tiboio.adb,
	libgnat/a-wwboio.adb, libgnat/a-zzboio.adb, libgnat/i-cobol.adb,
	libgnat/s-bitops.adb, libgnat/s-bitops.ads,
	libgnat/s-direio.adb, libgnat/s-dwalin.adb,
	libgnat/s-geveop.adb, libgnat/s-mmosin__unix.adb,
	libgnat/s-os_lib.adb, libgnat/s-os_lib.ads,
	libgnat/s-pooglo.ads, libgnat/s-secsta.adb,
	libgnat/s-shasto.adb, libgnat/s-stausa.ads,
	libgnat/s-stratt.ads, libgnat/s-ststop.adb: Remove with of
	parent.
	* sinfo.ads: Minor comment fix.
diff mbox series

Patch

diff --git a/gcc/ada/fname-sf.adb b/gcc/ada/fname-sf.adb
--- a/gcc/ada/fname-sf.adb
+++ b/gcc/ada/fname-sf.adb
@@ -24,7 +24,6 @@ 
 ------------------------------------------------------------------------------
 
 with Casing;        use Casing;
-with Fname;         use Fname;
 with Fname.UF;      use Fname.UF;
 with SFN_Scan;      use SFN_Scan;
 with Osint;         use Osint;


diff --git a/gcc/ada/libgnarl/s-stusta.adb b/gcc/ada/libgnarl/s-stusta.adb
--- a/gcc/ada/libgnarl/s-stusta.adb
+++ b/gcc/ada/libgnarl/s-stusta.adb
@@ -29,8 +29,6 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with System.Stack_Usage;
-
 --  This is why this package is part of GNARL:
 
 with System.Tasking.Debug;


diff --git a/gcc/ada/libgnarl/s-tasdeb.ads b/gcc/ada/libgnarl/s-tasdeb.ads
--- a/gcc/ada/libgnarl/s-tasdeb.ads
+++ b/gcc/ada/libgnarl/s-tasdeb.ads
@@ -32,7 +32,6 @@ 
 --  This package encapsulates all direct interfaces to task debugging services
 --  that are needed by gdb with gnat mode.
 
-with System.Tasking;
 with System.OS_Interface;
 
 package System.Tasking.Debug is


diff --git a/gcc/ada/libgnat/a-calfor.adb b/gcc/ada/libgnat/a-calfor.adb
--- a/gcc/ada/libgnat/a-calfor.adb
+++ b/gcc/ada/libgnat/a-calfor.adb
@@ -29,7 +29,6 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with Ada.Calendar;            use Ada.Calendar;
 with Ada.Calendar.Time_Zones; use Ada.Calendar.Time_Zones;
 
 package body Ada.Calendar.Formatting is


diff --git a/gcc/ada/libgnat/a-tiboio.adb b/gcc/ada/libgnat/a-tiboio.adb
--- a/gcc/ada/libgnat/a-tiboio.adb
+++ b/gcc/ada/libgnat/a-tiboio.adb
@@ -29,7 +29,6 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with Ada.Text_IO; use Ada.Text_IO;
 with Ada.Unchecked_Deallocation;
 
 package body Ada.Text_IO.Bounded_IO is


diff --git a/gcc/ada/libgnat/a-wwboio.adb b/gcc/ada/libgnat/a-wwboio.adb
--- a/gcc/ada/libgnat/a-wwboio.adb
+++ b/gcc/ada/libgnat/a-wwboio.adb
@@ -29,7 +29,6 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;
 with Ada.Unchecked_Deallocation;
 
 package body Ada.Wide_Text_IO.Wide_Bounded_IO is


diff --git a/gcc/ada/libgnat/a-zzboio.adb b/gcc/ada/libgnat/a-zzboio.adb
--- a/gcc/ada/libgnat/a-zzboio.adb
+++ b/gcc/ada/libgnat/a-zzboio.adb
@@ -29,7 +29,6 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with Ada.Wide_Wide_Text_IO; use Ada.Wide_Wide_Text_IO;
 with Ada.Unchecked_Deallocation;
 
 package body Ada.Wide_Wide_Text_IO.Wide_Wide_Bounded_IO is


diff --git a/gcc/ada/libgnat/i-cobol.adb b/gcc/ada/libgnat/i-cobol.adb
--- a/gcc/ada/libgnat/i-cobol.adb
+++ b/gcc/ada/libgnat/i-cobol.adb
@@ -34,8 +34,7 @@ 
 --  particular COBOL format is completely contained in the private part of
 --  the spec.
 
-with Interfaces; use Interfaces;
-with System;     use System;
+with System; use System;
 with Ada.Unchecked_Conversion;
 
 package body Interfaces.COBOL is


diff --git a/gcc/ada/libgnat/s-bitops.adb b/gcc/ada/libgnat/s-bitops.adb
--- a/gcc/ada/libgnat/s-bitops.adb
+++ b/gcc/ada/libgnat/s-bitops.adb
@@ -29,8 +29,7 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with System;                 use System;
-with System.Unsigned_Types;  use System.Unsigned_Types;
+with System.Unsigned_Types; use System.Unsigned_Types;
 
 with Ada.Exceptions;         use Ada.Exceptions;
 with Ada.Unchecked_Conversion;


diff --git a/gcc/ada/libgnat/s-bitops.ads b/gcc/ada/libgnat/s-bitops.ads
--- a/gcc/ada/libgnat/s-bitops.ads
+++ b/gcc/ada/libgnat/s-bitops.ads
@@ -31,8 +31,6 @@ 
 
 --  Operations on packed bit strings
 
-with System;
-
 package System.Bit_Ops is
 
    --  Note: in all the following routines, the System.Address parameters


diff --git a/gcc/ada/libgnat/s-direio.adb b/gcc/ada/libgnat/s-direio.adb
--- a/gcc/ada/libgnat/s-direio.adb
+++ b/gcc/ada/libgnat/s-direio.adb
@@ -32,7 +32,6 @@ 
 with Ada.IO_Exceptions;          use Ada.IO_Exceptions;
 with Ada.Unchecked_Deallocation;
 with Interfaces.C_Streams;       use Interfaces.C_Streams;
-with System;                     use System;
 with System.CRTL;
 with System.File_IO;
 with System.Soft_Links;


diff --git a/gcc/ada/libgnat/s-dwalin.adb b/gcc/ada/libgnat/s-dwalin.adb
--- a/gcc/ada/libgnat/s-dwalin.adb
+++ b/gcc/ada/libgnat/s-dwalin.adb
@@ -35,7 +35,6 @@  with Ada.Unchecked_Deallocation;
 
 with Interfaces; use Interfaces;
 
-with System;                   use System;
 with System.Address_Image;
 with System.Bounded_Strings;   use System.Bounded_Strings;
 with System.IO;                use System.IO;


diff --git a/gcc/ada/libgnat/s-geveop.adb b/gcc/ada/libgnat/s-geveop.adb
--- a/gcc/ada/libgnat/s-geveop.adb
+++ b/gcc/ada/libgnat/s-geveop.adb
@@ -29,7 +29,6 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with System;                    use System;
 with System.Address_Operations; use System.Address_Operations;
 with System.Storage_Elements;   use System.Storage_Elements;
 


diff --git a/gcc/ada/libgnat/s-mmosin__unix.adb b/gcc/ada/libgnat/s-mmosin__unix.adb
--- a/gcc/ada/libgnat/s-mmosin__unix.adb
+++ b/gcc/ada/libgnat/s-mmosin__unix.adb
@@ -30,7 +30,6 @@ 
 ------------------------------------------------------------------------------
 
 with Ada.IO_Exceptions;
-with System; use System;
 
 with System.OS_Lib; use System.OS_Lib;
 with System.Mmap.Unix; use System.Mmap.Unix;


diff --git a/gcc/ada/libgnat/s-os_lib.adb b/gcc/ada/libgnat/s-os_lib.adb
--- a/gcc/ada/libgnat/s-os_lib.adb
+++ b/gcc/ada/libgnat/s-os_lib.adb
@@ -31,7 +31,6 @@ 
 
 with Ada.Unchecked_Conversion;
 with Ada.Unchecked_Deallocation;
-with System; use System;
 with System.Case_Util;
 with System.CRTL;
 with System.Soft_Links;


diff --git a/gcc/ada/libgnat/s-os_lib.ads b/gcc/ada/libgnat/s-os_lib.ads
--- a/gcc/ada/libgnat/s-os_lib.ads
+++ b/gcc/ada/libgnat/s-os_lib.ads
@@ -48,7 +48,6 @@ 
 --  be used by other predefined packages. User access to this package is via
 --  a renaming of this package in GNAT.OS_Lib (file g-os_lib.ads).
 
-with System;
 with System.Strings;
 
 package System.OS_Lib is


diff --git a/gcc/ada/libgnat/s-pooglo.ads b/gcc/ada/libgnat/s-pooglo.ads
--- a/gcc/ada/libgnat/s-pooglo.ads
+++ b/gcc/ada/libgnat/s-pooglo.ads
@@ -32,7 +32,6 @@ 
 --  Storage pool corresponding to default global storage pool used for types
 --  for which no storage pool is specified.
 
-with System;
 with System.Storage_Pools;
 with System.Storage_Elements;
 


diff --git a/gcc/ada/libgnat/s-secsta.adb b/gcc/ada/libgnat/s-secsta.adb
--- a/gcc/ada/libgnat/s-secsta.adb
+++ b/gcc/ada/libgnat/s-secsta.adb
@@ -32,7 +32,6 @@ 
 with Ada.Unchecked_Conversion;
 with Ada.Unchecked_Deallocation;
 
-with System;                  use System;
 with System.Parameters;       use System.Parameters;
 with System.Soft_Links;       use System.Soft_Links;
 with System.Storage_Elements; use System.Storage_Elements;


diff --git a/gcc/ada/libgnat/s-shasto.adb b/gcc/ada/libgnat/s-shasto.adb
--- a/gcc/ada/libgnat/s-shasto.adb
+++ b/gcc/ada/libgnat/s-shasto.adb
@@ -36,7 +36,6 @@  with Ada.Streams.Stream_IO;
 with System.Global_Locks;
 with System.Soft_Links;
 
-with System;
 with System.CRTL;
 with System.File_Control_Block;
 with System.File_IO;


diff --git a/gcc/ada/libgnat/s-stausa.ads b/gcc/ada/libgnat/s-stausa.ads
--- a/gcc/ada/libgnat/s-stausa.ads
+++ b/gcc/ada/libgnat/s-stausa.ads
@@ -29,7 +29,6 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with System;
 with System.Storage_Elements;
 with System.Address_To_Access_Conversions;
 with Interfaces;


diff --git a/gcc/ada/libgnat/s-stratt.ads b/gcc/ada/libgnat/s-stratt.ads
--- a/gcc/ada/libgnat/s-stratt.ads
+++ b/gcc/ada/libgnat/s-stratt.ads
@@ -37,7 +37,6 @@ 
 --  defined types, the subprogram for the corresponding root type is called
 --  with an appropriate conversion.
 
-with System;
 with System.Unsigned_Types;
 with Ada.Streams;
 


diff --git a/gcc/ada/libgnat/s-ststop.adb b/gcc/ada/libgnat/s-ststop.adb
--- a/gcc/ada/libgnat/s-ststop.adb
+++ b/gcc/ada/libgnat/s-ststop.adb
@@ -33,7 +33,6 @@  with Ada.IO_Exceptions;        use Ada.IO_Exceptions;
 with Ada.Streams;              use Ada.Streams;
 with Ada.Unchecked_Conversion;
 
-with System;                   use System;
 with System.Storage_Elements;  use System.Storage_Elements;
 with System.Stream_Attributes;
 


diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb
--- a/gcc/ada/sem_ch10.adb
+++ b/gcc/ada/sem_ch10.adb
@@ -268,6 +268,8 @@  package body Sem_Ch10 is
    ------------------------------
 
    procedure Analyze_Compilation_Unit (N : Node_Id) is
+      Unit_Node : constant Node_Id := Unit (N);
+
       procedure Check_Redundant_Withs
         (Context_Items      : List_Id;
          Spec_Context_Items : List_Id := No_List);
@@ -587,6 +589,13 @@  package body Sem_Ch10 is
                --  Standalone package spec or body check
 
                else
+                  if Is_Ancestor_Package (Entity (Name (Clause)),
+                                          Defining_Entity (Unit_Node))
+                  then
+                     Error_Msg_N
+                       ("unnecessary with of ancestor?r?", Clause);
+                  end if;
+
                   declare
                      Dummy  : Boolean := False;
                      Withed : Boolean := False;
@@ -617,7 +626,6 @@  package body Sem_Ch10 is
       --  Local variables
 
       Main_Cunit    : constant Node_Id := Cunit (Main_Unit);
-      Unit_Node     : constant Node_Id := Unit (N);
       Lib_Unit      : Node_Id          := Library_Unit (N);
       Par_Spec_Name : Unit_Name_Type;
       Spec_Id       : Entity_Id;


diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads
--- a/gcc/ada/sinfo.ads
+++ b/gcc/ada/sinfo.ads
@@ -200,7 +200,7 @@  package Sinfo is
 
    --  The exceptions to this rule occur with {DEFINING_IDENTIFIERS} in all
    --  contexts, which is handled as described in the previous section, and
-   --  with {,library_unit_NAME} in the N_With_Clause mode, which is handled
+   --  with {,library_unit_NAME} in the N_With_Clause node, which is handled
    --  using the First_Name and Last_Name flags, as further detailed in the
    --  description of the N_With_Clause node.