]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix visibility issue in nested instance with use clause for formal package
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 6 Oct 2025 19:36:56 +0000 (21:36 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 3 Nov 2025 14:15:15 +0000 (15:15 +0100)
The compiler gives a spurious visibility error for a formal object parameter
of a formal package with a use clause, present in a parent instance, when an
instance of a child generic unit is compiled, while this does not happen in
the same circumstances for a formal type parameter.

The discrepancy comes from the Check_Generic_Actuals procedure, which clears
the Is_Hidden flag on all the actuals of a generic instance, but only sets
the Is_Potentially_Use_Visible flag on the actuals for formal types.

The change also contains a fix for a pasto in Restore_Private_Views, which
is responsible for undoing the changes made by Check_Generic_Actuals.

gcc/ada/ChangeLog:

PR ada/122161
* sem_ch12.adb (Check_Generic_Actuals): Consistently set the
Is_Potentially_Use_Visible flag on actuals whenever the Is_Hidden
flag is cleared.
(Restore_Private_Views): Clear the Is_Potentially_Use_Visible flag
explicitly on the entities of an actual package.

gcc/ada/sem_ch12.adb

index deb19ee118e156cf4a1aa53be485dbfa25a25b5a..8d7378e35b9444449d48590be28071f49b1f837d 100644 (file)
@@ -8629,6 +8629,7 @@ package body Sem_Ch12 is
                     Box_Present (Parent (Associated_Formal_Package (E))));
 
                Set_Is_Hidden (E, False);
+               Set_Is_Potentially_Use_Visible (E, In_Use (Instance));
             end if;
 
          --  If this is a subprogram instance (in a wrapper package) the
@@ -8636,12 +8637,14 @@ package body Sem_Ch12 is
 
          elsif Is_Wrapper_Package (Instance) then
             Set_Is_Hidden (E, False);
+            Set_Is_Potentially_Use_Visible (E, In_Use (Instance));
 
          --  If the formal package is declared with a box, or if the formal
          --  parameter is defaulted, it is visible in the body.
 
          elsif Is_Formal_Box or else Is_Visible_Formal (E) then
             Set_Is_Hidden (E, False);
+            Set_Is_Potentially_Use_Visible (E, In_Use (Instance));
          end if;
 
          --  Check directly the type of the actual objects, including the
@@ -17302,7 +17305,7 @@ package body Sem_Ch12 is
                                  and then Renamed_Entity (Id) = Act_P;
 
                      Set_Is_Hidden (Id, True);
-                     Set_Is_Potentially_Use_Visible (Id, In_Use (Act_P));
+                     Set_Is_Potentially_Use_Visible (Id, False);
 
                      if Ekind (Id) = E_Package then
                         Restore_Nested_Formal (Id);