[Ada] Handle Iterated_Component_Association with Others_Choice
authorEd Schonberg <schonberg@adacore.com>
Mon, 21 Sep 2020 15:54:09 +0000 (11:54 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 26 Oct 2020 08:59:17 +0000 (04:59 -0400)
gcc/ada/

* exp_aggr.adb (Build_Array_Aggr_Code): If the aggregate
includes an Others_Choice in an association that is an
Iterated_Component_Association, generate a proper loop for it.

gcc/ada/exp_aggr.adb

index 469777f..986ccc9 100644 (file)
@@ -2448,18 +2448,30 @@ package body Exp_Aggr is
             Next (Expr);
          end loop;
 
-         --  STEP 2 (b): Generate final loop if an others choice is present
+         --  STEP 2 (b): Generate final loop if an others choice is present.
          --  Here Nb_Elements gives the offset of the last positional element.
 
          if Present (Component_Associations (N)) then
             Assoc := Last (Component_Associations (N));
 
-            --  Ada 2005 (AI-287)
+            if Nkind (Assoc) = N_Iterated_Component_Association then
+               --  Ada 2020: generate a loop to have a proper scope for
+               --  the identifier that typically appears in the expression.
+               --  The lower bound of the loop is the position after all
+               --  previous positional components.
 
-            Append_List (Gen_While (Add (Nb_Elements, To => Aggr_L),
-                                    Aggr_High,
-                                    Get_Assoc_Expr (Assoc)), --  AI-287
-                         To => New_Code);
+               Append_List (Gen_Loop (Add (Nb_Elements + 1, To => Aggr_L),
+                                      Aggr_High,
+                                      Expression (Assoc)),
+                            To => New_Code);
+            else
+               --  Ada 2005 (AI-287)
+
+               Append_List (Gen_While (Add (Nb_Elements, To => Aggr_L),
+                                       Aggr_High,
+                                       Get_Assoc_Expr (Assoc)),
+                            To => New_Code);
+            end if;
          end if;
       end if;