diff mbox series

[Ada] Mixing of positional and named entries allowed in enum rep

Message ID 20210616084355.GA95486@adacore.com
State New
Headers show
Series [Ada] Mixing of positional and named entries allowed in enum rep | expand

Commit Message

Pierre-Marie de Rodat June 16, 2021, 8:43 a.m. UTC
This patch fixes an issue in the compiler whereby the mixing of
positional and named entries in an enumeration representation clause was
erroneously allowed instead of rejected - as per RM rules.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* sem_ch13.adb (Analyze_Enumeration_Representation_Clause): Add
	check for the mixing of entries.
diff mbox series

Patch

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -7999,6 +7999,15 @@  package body Sem_Ch13 is
            ("extra parentheses surrounding aggregate not allowed", Aggr);
          return;
 
+      --  Reject the mixing of named and positional entries in the aggregate
+
+      elsif Present (Expressions (Aggr))
+        and then Present (Component_Associations (Aggr))
+      then
+         Error_Msg_N ("cannot mix positional and named entries in "
+                       & "enumeration rep clause", N);
+         return;
+
       --  All tests passed, so set rep clause in place
 
       else
@@ -8013,7 +8022,7 @@  package body Sem_Ch13 is
 
       Elit := First_Literal (Enumtype);
 
-      --  First the positional entries if any
+      --  Process positional entries
 
       if Present (Expressions (Aggr)) then
          Expr := First (Expressions (Aggr));
@@ -8042,11 +8051,10 @@  package body Sem_Ch13 is
             Next (Expr);
             Next (Elit);
          end loop;
-      end if;
 
-      --  Now process the named entries if present
+      --  Process named entries
 
-      if Present (Component_Associations (Aggr)) then
+      elsif Present (Component_Associations (Aggr)) then
          Assoc := First (Component_Associations (Aggr));
          while Present (Assoc) loop
             Choice := First (Choices (Assoc));