]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Ada: Fix regression in visibility for nested use_type_clauses
authorGary Dismukes <dismukes@adacore.com>
Fri, 30 Jan 2026 16:55:16 +0000 (17:55 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Fri, 30 Jan 2026 17:47:56 +0000 (18:47 +0100)
An earlier fix for wrong handling of visibility when a use_type_clause
with "all" occurs within a nested scope when there's a use_type_clause
in an enclosing scope without "all" was incorrect and led to primitives
being visible in a later nested scope that has a use_type_clause with
"all" for the same type.  We now properly restore Current_Use_Clause
to refer to the outer use_type_clause when ending the scope of nested
use_type_clauses.

gcc/ada/
* sem_ch8.adb (End_Use_Type): Remove test of Prev_Use_Clause as
as a condition for resetting In_Use and Current_Use_Clause, and
change setting of that flag and field based on Prev_Use_Clause
rather than setting them to Empty. Revise preceding comment.

gcc/ada/sem_ch8.adb

index 4a5a5ab4a5408350bf5444698a9fad92f506591c..2aa3021cfa628913a654743a896fe751425d165a 100644 (file)
@@ -5516,19 +5516,14 @@ package body Sem_Ch8 is
          elsif In_Open_Scopes (Scope (Base_Type (T))) then
             null;
 
-         --  Turn off the use_type_clause on the type unless the clause is
-         --  redundant, or there's a previous use_type_clause. (The case where
-         --  a use_type_clause without "all" is followed by one with "all" in
-         --  a more nested scope is not considered redundant, necessitating
-         --  the test for a previous clause. One might expect the latter test
-         --  to suffice, but it turns out there are cases where Redundant_Use
-         --  is set, but Prev_Use_Clause is not set. ???)
-
-         elsif not Redundant_Use (Id) and then No (Prev_Use_Clause (N)) then
-            Set_In_Use (T, False);
-            Set_In_Use (Base_Type (T), False);
-            Set_Current_Use_Clause (T, Empty);
-            Set_Current_Use_Clause (Base_Type (T), Empty);
+         --  Reinstate a previous use_type_clause (if any) on the type unless
+         --  the current use_type_clause is redundant.
+
+         elsif not Redundant_Use (Id) then
+            Set_In_Use (T, Present (Prev_Use_Clause (N)));
+            Set_In_Use (Base_Type (T), Present (Prev_Use_Clause (N)));
+            Set_Current_Use_Clause (T, Prev_Use_Clause (N));
+            Set_Current_Use_Clause (Base_Type (T), Prev_Use_Clause (N));
 
             --  See Use_One_Type for the rationale. This is a bit on the naive
             --  side, but should be good enough in practice.