]> gcc.gnu.org Git - gcc.git/commitdiff
[Ada] Additional error checking on index constraints with fixed-lower-bound ranges
authorGary Dismukes <dismukes@adacore.com>
Tue, 23 Mar 2021 23:03:23 +0000 (19:03 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Fri, 18 Jun 2021 08:36:54 +0000 (04:36 -0400)
gcc/ada/

* sem_ch3.adb (Constrain_Array): Add error checking for
fixed-lower-bound and constrained index ranges applied
inappropriately on subtypes of unconstrained and
fixed-lower-bound array types.
(Constrain_Index): Correct and refine comment related to
fixed-lower-bound index ranges.

gcc/ada/sem_ch3.adb

index 9ef937df71ea436909de46d7e8002e5efd110dc5..4982fcd4721f625ea6b1d8cb122155259d943b37 100644 (file)
@@ -13373,8 +13373,40 @@ package body Sem_Ch3 is
                --  entity will need to be marked as being a fixed-lower-bound
                --  array subtype.
 
-               if Is_Fixed_Lower_Bound_Index_Subtype (Etype (S)) then
-                  Is_FLB_Array_Subtype := True;
+               if S = First (Constraints (C)) then
+                  Is_FLB_Array_Subtype :=
+                    Is_Fixed_Lower_Bound_Index_Subtype (Etype (S));
+
+                  --  If the parent subtype (or should this be Etype of that?)
+                  --  is an FLB array subtype, we flag an error, because we
+                  --  don't currently allow subtypes of such subtypes to
+                  --  specify a fixed lower bound for any of their indexes,
+                  --  even if the index of the parent subtype is a "range <>"
+                  --  index.
+
+                  if Is_FLB_Array_Subtype
+                    and then Is_Fixed_Lower_Bound_Array_Subtype (T)
+                  then
+                     Error_Msg_NE
+                       ("index with fixed lower bound not allowed for subtype "
+                          & "of fixed-lower-bound }", S, T);
+
+                     Is_FLB_Array_Subtype := False;
+                  end if;
+
+               elsif Is_FLB_Array_Subtype
+                 and then not Is_Fixed_Lower_Bound_Index_Subtype (Etype (S))
+               then
+                  Error_Msg_NE
+                    ("constrained index not allowed for fixed-lower-bound "
+                       & "subtype of}", S, T);
+
+               elsif not Is_FLB_Array_Subtype
+                 and then Is_Fixed_Lower_Bound_Index_Subtype (Etype (S))
+               then
+                  Error_Msg_NE
+                    ("index with fixed lower bound not allowed for "
+                       & "constrained subtype of}", S, T);
                end if;
 
                Next (Index);
@@ -14396,9 +14428,9 @@ package body Sem_Ch3 is
       Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
 
       --  If this is a range for a fixed-lower-bound subtype, then set the
-      --  index itype's lower bound to the FLB and the index type's upper bound
-      --  to the high bound of the index subtype's high bound, mark the itype
-      --  as an FLB index subtype, and set the range's Etype to the itype.
+      --  index itype's low bound to the FLB and the index itype's upper bound
+      --  to the high bound of the parent array type's index subtype. Also,
+      --  mark the itype as an FLB index subtype.
 
       if Nkind (S) = N_Range and then Is_FLB_Index then
          Set_Scalar_Range
This page took 0.089164 seconds and 5 git commands to generate.