https://gcc.gnu.org/g:e95656d98401f820227a194de20233256c511f85

commit r16-4968-ge95656d98401f820227a194de20233256c511f85
Author: Eric Botcazou <[email protected]>
Date:   Mon Oct 6 21:36:56 2025 +0200

    ada: Fix visibility issue in nested instance with use clause for formal 
package
    
    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.

Diff:
---
 gcc/ada/sem_ch12.adb | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index deb19ee118e1..8d7378e35b94 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -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);

Reply via email to