https://gcc.gnu.org/g:ed185d8310535907654bb282531cdf6b05069dd6

commit r15-10751-ged185d8310535907654bb282531cdf6b05069dd6
Author: Eric Botcazou <[email protected]>
Date:   Thu Jan 29 16:16:08 2026 +0100

    Ada: Fix internal error on equality test with empty container
    
    This is a regression present on the mainline and 15 branch, although the
    root cause has been present for years: the Sem_Type.Covers predicate
    returns true for the type of an aggregate (Any_Composite) and any type
    declared with the Aggregate aspect (when invoked in Ada 2022 or later),
    but its companion function Sem_Type.Specific_Type punts when it is called
    on the same combination.
    
    gcc/ada/
            PR ada/123861
            * sem_type.adb (Covers): Fix couple of typos in comment.
            (Specific_Type): Adjust to Covers' handling of types declared
            with the Aggregate aspect in Ada 2022.
    
    gcc/testsuite/
            * gnat.dg/specs/aggr11.ads: New test.

Diff:
---
 gcc/ada/sem_type.adb                   | 10 ++++++++--
 gcc/testsuite/gnat.dg/specs/aggr11.ads | 17 +++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_type.adb b/gcc/ada/sem_type.adb
index d070230893d7..144e83e742e8 100644
--- a/gcc/ada/sem_type.adb
+++ b/gcc/ada/sem_type.adb
@@ -1012,8 +1012,8 @@ package body Sem_Type is
       elsif T2 = Any_Composite and then Is_Aggregate_Type (T1) then
          return True;
 
-      --  In Ada_2022, an aggregate is compatible with the type that
-      --  as the corresponding aspect.
+      --  In Ada 2022, an aggregate is compatible with the type that
+      --  has the corresponding aspect.
 
       elsif Ada_Version >= Ada_2022
         and then T2 = Any_Composite
@@ -3371,6 +3371,9 @@ package body Sem_Type is
         or else (T1 = Any_Character     and then Is_Character_Type (T2))
         or else (T1 = Any_String        and then Is_String_Type (T2))
         or else (T1 = Any_Composite     and then Is_Aggregate_Type (T2))
+        or else (Ada_Version >= Ada_2022
+                  and then T1 = Any_Composite
+                  and then Has_Aspect (T2, Aspect_Aggregate))
       then
          return B2;
 
@@ -3391,6 +3394,9 @@ package body Sem_Type is
         or else (T2 = Any_Character     and then Is_Character_Type (T1))
         or else (T2 = Any_String        and then Is_String_Type (T1))
         or else (T2 = Any_Composite     and then Is_Aggregate_Type (T1))
+        or else (Ada_Version >= Ada_2022
+                  and then T2 = Any_Composite
+                  and then Has_Aspect (T1, Aspect_Aggregate))
       then
          return B1;
 
diff --git a/gcc/testsuite/gnat.dg/specs/aggr11.ads 
b/gcc/testsuite/gnat.dg/specs/aggr11.ads
new file mode 100644
index 000000000000..b0dd57884cee
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/aggr11.ads
@@ -0,0 +1,17 @@
+-- PR ada/123861
+-- { dg-do compile }
+-- { dg-options "-gnat2022" }
+
+with Ada.Containers.Vectors;
+
+package Aggr11 is
+
+  package Vectors is new Ada.Containers.Vectors (Positive, Integer);
+  use Vectors;
+
+  A : constant Vector  := [];
+  B : constant Boolean := [] = A;        -- ICE
+  C : constant Boolean := Vector'[] = A; -- Works
+  D : constant Boolean := A = [];        -- Works
+
+end Aggr11;

Reply via email to