]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Fix internal error on untagged record type with equality operator
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 1 Jul 2022 08:47:36 +0000 (10:47 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 13 Jul 2022 10:01:14 +0000 (10:01 +0000)
After the binding interpretation issued under AI12-0413, a user-defined
primitive equality operator of an untagged record type hides the predefined
equality operator in an instantiation, but this does not apply if the
instantiation appears in the same declarative region as the type and
before the declaration of this user-defined operator.

gcc/ada/

* sem_res.adb (Resolve_Equality_Op): Make sure that the user-defined
operator of an untagged record type is declared ahead of an instance
before using it to resolve the equality operator in the instance.

gcc/ada/sem_res.adb

index 44fc955de74a5394ace16e149fcf998398faa110..1412d94198c7b08a01d0ab96c7271b44c16e9e64 100644 (file)
@@ -8967,7 +8967,14 @@ package body Sem_Res is
                then
                   Eq := Get_User_Defined_Equality (T);
 
-                  if Present (Eq) then
+                  --  We need to make sure that the instance is not within the
+                  --  same declarative region as the type, or else that it lies
+                  --  after the declaration of the user-defined "=" operator.
+
+                  if Present (Eq)
+                    and then (not In_Same_Extended_Unit (Eq, N)
+                               or else Earlier_In_Extended_Unit (Eq, N))
+                  then
                      if Is_Abstract_Subprogram (Eq) then
                         Nondispatching_Call_To_Abstract_Operation (N, Eq);
                      else