]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Simplify code for private types with unknown discriminants
authorPiotr Trojanek <trojanek@adacore.com>
Tue, 5 Mar 2024 12:06:18 +0000 (13:06 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Fri, 17 May 2024 08:21:00 +0000 (10:21 +0200)
Private type entities have Is_Constrained set when they have no
discriminants and no unknown discriminants; it is now set slightly
later, but simpler (this change could only affect Process_Discriminants,
but this flag should not be needed there).

Also, we now reuse this flag to detect private types with discriminants.

Code cleanup; behavior is unaffected.

gcc/ada/

* sem_ch7.adb (New_Private_Type): Simplify setting of
Is_Constrained flag.
* sem_prag.adb (Is_Unconstrained_Or_Tagged_Item): Simplify
detection of private types with no discriminant.

gcc/ada/sem_ch7.adb
gcc/ada/sem_prag.adb

index 746462244529e681d6d11842046198f3a06c6c80..a70d72c94c1ee2f9bfa5a790b3ff2ff4086e3fa4 100644 (file)
@@ -2746,10 +2746,6 @@ package body Sem_Ch7 is
       Set_Is_First_Subtype (Id);
       Reinit_Size_Align (Id);
 
-      Set_Is_Constrained (Id,
-        No (Discriminant_Specifications (N))
-          and then not Unknown_Discriminants_Present (N));
-
       --  Set tagged flag before processing discriminants, to catch illegal
       --  usage.
 
@@ -2765,6 +2761,9 @@ package body Sem_Ch7 is
 
       elsif Unknown_Discriminants_Present (N) then
          Set_Has_Unknown_Discriminants (Id);
+
+      else
+         Set_Is_Constrained (Id);
       end if;
 
       Set_Private_Dependents (Id, New_Elmt_List);
index 0302cdb00ba59ae5084668b36dc0a4cd1f73af20..e57f42d9a54d5081246c285bcd181c4aaf48043d 100644 (file)
@@ -32978,8 +32978,7 @@ package body Sem_Prag is
          return Has_Discriminants (Typ) and then not Is_Constrained (Typ);
 
       elsif Is_Private_Type (Typ) then
-         return Has_Discriminants (Typ)
-           or else Has_Unknown_Discriminants (Typ);
+         return not Is_Constrained (Typ);
 
       else
          return False;