From: Denis Mazzucato <mazzuc...@adacore.com>

This patch improves the warning message when the actual file name of a child
package with a single letter parent isn't the expected one because it may
collide with a predefined unit name. The warning explain why in this specific
case the expected name is not the standard one using the minus to separate
parents with children.

gcc/ada/ChangeLog:

        * par-load.adb (Load): Better warning message.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/par-load.adb | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/par-load.adb b/gcc/ada/par-load.adb
index 4a97f14ffb51..0206b56e174f 100644
--- a/gcc/ada/par-load.adb
+++ b/gcc/ada/par-load.adb
@@ -117,6 +117,29 @@ procedure Load is
 
    end Same_File_Name_Except_For_Case;
 
+   function Actual_Name_Collides_With_Predefined_Unit_Name
+     (Actual_File_Name : File_Name_Type) return Boolean;
+   --  Given an actual file name, determine if it is a child unit whose parent
+   --  unit is a single letter that is a, g, i, or s. Such a name could create
+   --  confusion with predefined units and thus is required to use a tilde
+   --  instead of the minus as the second character.
+
+   ----------------------------------------------------
+   -- Actual_Name_Collides_With_Predefined_Unit_Name --
+   ----------------------------------------------------
+
+   function Actual_Name_Collides_With_Predefined_Unit_Name
+     (Actual_File_Name : File_Name_Type) return Boolean
+   is
+      N1 : Character;
+   begin
+      Get_Name_String (Actual_File_Name);
+      N1 := Name_Buffer (1);
+      return Name_Len > 1
+        and then Name_Buffer (2) = '-'
+        and then (N1 = 'a' or else N1 = 'g' or else N1 = 'i' or else N1 = 's');
+   end Actual_Name_Collides_With_Predefined_Unit_Name;
+
 --  Start of processing for Load
 
 begin
@@ -163,8 +186,18 @@ begin
                          (File_Name, Unit_File_Name (Cur_Unum)))
    then
       Error_Msg_File_1 := File_Name;
-      Error_Msg
-        ("??file name does not match unit name, should be{", Sloc (Curunit));
+      if Actual_Name_Collides_With_Predefined_Unit_Name
+           (Unit_File_Name (Cur_Unum))
+      then
+         Error_Msg
+           ("??file name may conflict with predefined units, "
+            & "the expected file name for this unit is{",
+            Sloc (Curunit));
+      else
+         Error_Msg
+           ("??file name does not match unit name, should be{",
+            Sloc (Curunit));
+      end if;
    end if;
 
    --  For units other than the main unit, the expected unit name is set and
-- 
2.43.0

Reply via email to