aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorGary Dismukes <dismukes@adacore.com>2023-12-02 00:11:31 +0000
committerMarc Poulhiès <poulhies@adacore.com>2023-12-19 15:27:50 +0100
commitaad881afce9edba1ccb16305c2796987c6af2543 (patch)
tree12080c6d12c8a5cccc8ae688a1f64a7fd01f0f71 /gcc/ada
parent8ce9496f0e18f2cd1a0b86d18c534bd04fbacc31 (diff)
downloadgcc-aad881afce9edba1ccb16305c2796987c6af2543.zip
gcc-aad881afce9edba1ccb16305c2796987c6af2543.tar.gz
gcc-aad881afce9edba1ccb16305c2796987c6af2543.tar.bz2
ada: Missing error on positional container aggregates for types with Add_Named
The compiler fails to reject a container aggregate written using positional notation when the container type specifies an Add_Named operation in its Aggregate aspect. Container aggregates for such types must be written using named associations. The compiler ignores the positional associations and produces an empty aggregate object. An error check is added to catch such illegal container aggregates. gcc/ada/ * sem_aggr.adb (Resolve_Container_Aggregate): In the Add_Named case, issue an error if the container aggregate is written as a positional aggregate, since such an aggregate must have named associations.
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/sem_aggr.adb20
1 files changed, 17 insertions, 3 deletions
diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index bf24962..1027acf 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -3436,11 +3436,25 @@ package body Sem_Aggr is
Key_Type : constant Entity_Id := Etype (Next_Formal (Container));
Elmt_Type : constant Entity_Id :=
Etype (Next_Formal (Next_Formal (Container)));
- Comp : Node_Id;
- Choice : Node_Id;
+
+ Comp_Assocs : constant List_Id := Component_Associations (N);
+ Comp : Node_Id;
+ Choice : Node_Id;
begin
- Comp := First (Component_Associations (N));
+ -- In the Add_Named case, the aggregate must consist of named
+ -- associations (Add_Unnnamed is not allowed), so we issue an
+ -- error if there are positional associations.
+
+ if not Present (Comp_Assocs)
+ and then Present (Expressions (N))
+ then
+ Error_Msg_N ("container aggregate must be "
+ & "named, not positional", N);
+ return;
+ end if;
+
+ Comp := First (Comp_Assocs);
while Present (Comp) loop
if Nkind (Comp) = N_Component_Association then
Choice := First (Choices (Comp));