]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Add Incomplete_Type_OK formal to Process_Subtype
authorRonan Desplanques <desplanques@adacore.com>
Tue, 18 Mar 2025 17:02:29 +0000 (18:02 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 10 Jun 2025 07:32:03 +0000 (09:32 +0200)
Before this patch, Process_Subtype looked at the parent of its argument
to determine whether it was called in a context where it was OK for the
subtype mark to refer to the incomplete view of a type. This patch adds
a new formal so that it becomes the responsibility of the caller in
order to make the code simpler overall.

The only change in the behavior of the compiler is that the messages
emitted in some error situations with the -gnatf switch are slightly
different.

gcc/ada/ChangeLog:

* sem_ch3.ads (Process_Subtype): New formal.
* sem_ch3.adb (Process_Subtype): Likewise.
(Analyze_Subtype_Declaration, Access_Type_Declaration): Use new
formal.

gcc/ada/sem_ch3.adb
gcc/ada/sem_ch3.ads

index fdf225efc30ad40dbdde75dcf265395446edb9ec..823cc34e22b621bdb474549d15dd639d8af6651a 100644 (file)
@@ -1414,7 +1414,9 @@ package body Sem_Ch3 is
          end if;
 
       else
-         Setup_Access_Type (Desig_Typ => Process_Subtype (S, P, T, 'P'));
+         Setup_Access_Type
+           (Desig_Typ =>
+              Process_Subtype (S, P, T, 'P', Incomplete_Type_OK => True));
       end if;
 
       if not Error_Posted (T) then
@@ -5775,7 +5777,9 @@ package body Sem_Ch3 is
            N,
            Id,
            'P',
-           Excludes_Null => Null_Exclusion_Present (N));
+           Excludes_Null      => Null_Exclusion_Present (N),
+           Incomplete_Type_OK =>
+             Ada_Version >= Ada_2005 or else Is_Itype (Id));
 
       --  Class-wide equivalent types of records with unknown discriminants
       --  involve the generation of an itype which serves as the private view
@@ -22523,11 +22527,12 @@ package body Sem_Ch3 is
    ---------------------
 
    function Process_Subtype
-     (S             : Node_Id;
-      Related_Nod   : Node_Id;
-      Related_Id    : Entity_Id := Empty;
-      Suffix        : Character := ' ';
-      Excludes_Null : Boolean := False) return Entity_Id
+     (S                  : Node_Id;
+      Related_Nod        : Node_Id;
+      Related_Id         : Entity_Id := Empty;
+      Suffix             : Character := ' ';
+      Excludes_Null      : Boolean := False;
+      Incomplete_Type_OK : Boolean := False) return Entity_Id
    is
       procedure Check_Incomplete (T : Node_Id);
       --  Called to verify that an incomplete type is not used prematurely
@@ -22541,13 +22546,7 @@ package body Sem_Ch3 is
          --  Ada 2005 (AI-412): Incomplete subtypes are legal
 
          if Ekind (Root_Type (Entity (T))) = E_Incomplete_Type
-           and then
-             not (Ada_Version >= Ada_2005
-                   and then
-                     (Nkind (Parent (T)) = N_Subtype_Declaration
-                       or else (Nkind (Parent (T)) = N_Subtype_Indication
-                                 and then Nkind (Parent (Parent (T))) =
-                                                   N_Subtype_Declaration)))
+           and then not Incomplete_Type_OK
          then
             Error_Msg_N ("invalid use of type before its full declaration", T);
          end if;
@@ -22643,13 +22642,7 @@ package body Sem_Ch3 is
       else
          Find_Type (Subtype_Mark (S));
 
-         if Nkind (Parent (S)) /= N_Access_To_Object_Definition
-           and then not
-            (Nkind (Parent (S)) = N_Subtype_Declaration
-              and then Is_Itype (Defining_Identifier (Parent (S))))
-         then
-            Check_Incomplete (Subtype_Mark (S));
-         end if;
+         Check_Incomplete (Subtype_Mark (S));
 
          Subtype_Mark_Id := Entity (Subtype_Mark (S));
 
@@ -22707,7 +22700,12 @@ package body Sem_Ch3 is
 
             return
               Process_Subtype
-                (S, Related_Nod, Related_Id, Suffix, Excludes_Null);
+                (S,
+                 Related_Nod,
+                 Related_Id,
+                 Suffix,
+                 Excludes_Null,
+                 Incomplete_Type_OK);
          end if;
 
          --  Remaining processing depends on type. Select on Base_Type kind to
index d600d157e653369f5da68bb34b2fb6449854dd4a..a97393d3cfe8acce59557f6004212950d8d8e85d 100644 (file)
@@ -301,11 +301,12 @@ package Sem_Ch3 is
    --  in this case the bounds are captured if necessary using this name.
 
    function Process_Subtype
-     (S             : Node_Id;
-      Related_Nod   : Node_Id;
-      Related_Id    : Entity_Id := Empty;
-      Suffix        : Character := ' ';
-      Excludes_Null : Boolean := False) return Entity_Id;
+     (S                  : Node_Id;
+      Related_Nod        : Node_Id;
+      Related_Id         : Entity_Id := Empty;
+      Suffix             : Character := ' ';
+      Excludes_Null      : Boolean := False;
+      Incomplete_Type_OK : Boolean := False) return Entity_Id;
    --  Process a subtype indication S and return corresponding entity.
    --  Related_Nod is the node where the potential generated implicit types
    --  will be inserted. The Related_Id and Suffix parameters are used to