From: Denis Mazzucato Date: Tue, 12 Aug 2025 08:57:03 +0000 (+0200) Subject: ada: Better warning when single letter package conflicts with predefined unit naming X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a570b7407483b061f3e6b3c4c45dbb1b2df94167;p=thirdparty%2Fgcc.git ada: Better warning when single letter package conflicts with predefined unit naming 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. --- diff --git a/gcc/ada/par-load.adb b/gcc/ada/par-load.adb index 4a97f14ffb5..0206b56e174 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