]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Reject limited objects in array and record delta aggregates
authorPiotr Trojanek <trojanek@adacore.com>
Thu, 14 Oct 2021 21:31:21 +0000 (23:31 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 8 Nov 2022 08:34:58 +0000 (09:34 +0100)
For array delta aggregates the base expression cannot be limited; for
record delta aggregates the base expression can only be limited if it is
a newly constructed object.

gcc/ada/

* sem_aggr.adb (Resolve_Delta_Aggregate): Implement rules related
to limited objects appearing as the base expression.

gcc/ada/sem_aggr.adb

index 383f18f7301f473d27ab67dfb9e6d33aee4dd762..4da05dd731742e62796f6dfe4c587236f97eac85 100644 (file)
@@ -3421,6 +3421,18 @@ package body Sem_Aggr is
       Analyze_And_Resolve (Base, Typ);
 
       if Is_Array_Type (Typ) then
+         --  For an array_delta_aggregate, the base_expression and each
+         --  expression in every array_component_association shall be of a
+         --  nonlimited type; RM 4.3.4(13/5). However, to prevent repeated
+         --  errors we only check the base expression and not array component
+         --  associations.
+
+         if Is_Limited_Type (Etype (Base)) then
+            Error_Msg_N
+              ("array delta aggregate shall be of a nonlimited type", Base);
+            Explain_Limited_Type (Etype (Base), Base);
+         end if;
+
          Resolve_Delta_Array_Aggregate (N, Typ);
       else
 
@@ -3432,6 +3444,11 @@ package body Sem_Aggr is
               ("delta aggregates for record types must use (), not '[']", N);
          end if;
 
+         --  The base_expression of a record_delta_aggregate can be of a
+         --  limited type only if it is newly constructed; RM 7.5(2.1/5).
+
+         Check_Expr_OK_In_Limited_Aggregate (Base);
+
          Resolve_Delta_Record_Aggregate (N, Typ);
       end if;