[Ada] Improper error message on equality op with different operand types
authorEd Schonberg <schonberg@adacore.com>
Mon, 12 Aug 2019 09:00:59 +0000 (09:00 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Mon, 12 Aug 2019 09:00:59 +0000 (09:00 +0000)
2019-08-12  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

* sem_ch6.adb (heck_Untagged_Equality): Verify that user-defined
equality has the same profile as the predefined equality before
applying legality rule in RM 4.5.2 (9.8).

gcc/testsuite/

* gnat.dg/equal10.adb, gnat.dg/equal10.ads: New testcase.

From-SVN: r274297

gcc/ada/ChangeLog
gcc/ada/sem_ch6.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/equal10.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/equal10.ads [new file with mode: 0644]

index 351cc49015272a11e7b1307ea7299bf29c427ffc..3c22a90a21a5181e4c2e3480469f08450180dd83 100644 (file)
@@ -1,3 +1,9 @@
+2019-08-12  Ed Schonberg  <schonberg@adacore.com>
+
+       * sem_ch6.adb (heck_Untagged_Equality): Verify that user-defined
+       equality has the same profile as the predefined equality before
+       applying legality rule in RM 4.5.2 (9.8).
+
 2019-08-12  Bob Duff  <duff@adacore.com>
 
        * libgnat/a-except.ads: Update obsolete comment, still making
index 25ee7053ade7216efc9a132c2119d17ce4069062..3c026bf43b993afde6f91c7c855d6fc806e9ec48 100644 (file)
@@ -8420,11 +8420,12 @@ package body Sem_Ch6 is
 
    begin
       --  This check applies only if we have a subprogram declaration with an
-      --  untagged record type.
+      --  untagged record type that is conformant to the predefined op.
 
       if Nkind (Decl) /= N_Subprogram_Declaration
         or else not Is_Record_Type (Typ)
         or else Is_Tagged_Type (Typ)
+        or else Etype (Next_Formal (First_Formal (Eq_Op))) /= Typ
       then
          return;
       end if;
index 2918943d1aa965c632a2ab42e8560c539ff89d9f..ee519d4c21b42a3a80a991ca1810b36198440da9 100644 (file)
@@ -1,3 +1,7 @@
+2019-08-12  Ed Schonberg  <schonberg@adacore.com>
+
+       * gnat.dg/equal10.adb, gnat.dg/equal10.ads: New testcase.
+
 2019-08-12  Gary Dismukes  <dismukes@adacore.com>
 
        * gnat.dg/suppress_initialization2.adb,
diff --git a/gcc/testsuite/gnat.dg/equal10.adb b/gcc/testsuite/gnat.dg/equal10.adb
new file mode 100644 (file)
index 0000000..9b61e5e
--- /dev/null
@@ -0,0 +1,5 @@
+--  { dg-do compile }
+
+package body Equal10 is
+  procedure Dummy is null;
+end Equal10;
diff --git a/gcc/testsuite/gnat.dg/equal10.ads b/gcc/testsuite/gnat.dg/equal10.ads
new file mode 100644 (file)
index 0000000..28e1a21
--- /dev/null
@@ -0,0 +1,7 @@
+package Equal10 is
+  type R is record X : Integer; end record;
+  Rr : R;
+  function "=" (Y : R; Z : Integer) return Boolean is
+     (Y.X = Z);
+  procedure Dummy;
+end Equal10;