https://gcc.gnu.org/g:d02446b947aa6a2008abbeb891977db6c4b712e0
commit r16-9136-gd02446b947aa6a2008abbeb891977db6c4b712e0 Author: Eric Botcazou <[email protected]> Date: Fri May 29 10:54:05 2026 +0200 ada: Fix duplicated external tag error with structural generic instantiation The registration can be skipped altogether, because the name of the tag is quite unlikely to conflict with a user-declared tag. gcc/ada/ChangeLog: * sem_ch12.adb (Build_Structural_Instantiation): Temporarily disable registration of tagged types when analyzing the instantiation. Diff: --- gcc/ada/sem_ch12.adb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index 58692fb8e073..acbb47f29381 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -7405,10 +7405,21 @@ package body Sem_Ch12 is -- reasons pertaining to freezing (see the Freeze_Package_Instance and -- Freeze_Subprogram_Instance procedures). - Add_Local_Declaration (Inst, N, Scop => Empty); - if Error_Posted (Inst) then - return Empty; - end if; + -- We also need to temporarily disable registration of tagged types, + -- lest there be multiple instantiations in the partition, since it + -- is performed even though the generic unit is preelaborated. + + declare + S_Restrictions : constant Save_Cunit_Boolean_Restrictions := + Cunit_Boolean_Restrictions_Save; + begin + Set_Restriction (No_Tagged_Type_Registration, N); + Add_Local_Declaration (Inst, N, Scop => Empty); + Cunit_Boolean_Restrictions_Restore (S_Restrictions); + if Error_Posted (Inst) then + return Empty; + end if; + end; -- If the structural instance had already been created, this occurrence -- has been turned into a renaming of it.
