public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Missing error on positional container aggregates for types with Add_Named
@ 2023-12-19 14:31 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2023-12-19 14:31 UTC (permalink / raw)
  To: gcc-patches; +Cc: Gary Dismukes

From: Gary Dismukes <dismukes@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_aggr.adb | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index bf249620d04..1027acf20b5 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));
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-19 14:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-19 14:31 [COMMITTED] ada: Missing error on positional container aggregates for types with Add_Named Marc Poulhiès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).