The reproducer is made up of 9 units containing multiple level of nested
instances, but in the end the problem is that the final child unit has the
same name as the parameter in its instantiation, exposing the problematic
manipulation of the homonym chain done in Analyze_Subprogram_Instantiation.
The fix is to replace this manipulation with a call to Remove_Homonym.
Tested on x86-64/Linux, applied on the mainline.
2025-10-28 Eric Botcazou <[email protected]>
PR ada/48039
* sem_ch12.adb (Analyze_Subprogram_Instantiation): Call
Remove_Homonym to remove the enclosing package from visibility.
--
Eric Botcazoudiff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index 9acf1932678..1a05b0c6293 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -6735,7 +6735,7 @@ package body Sem_Ch12 is
-- Remove package itself from visibility, so it does not
-- conflict with subprogram.
- Set_Name_Entity_Id (Chars (Pack_Id), Homonym (Pack_Id));
+ Remove_Homonym (Pack_Id);
-- Set name and scope of internal subprogram so that the proper
-- external name will be generated. The proper scope is the scope