public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-829] [Ada] Restore hiding of predefined "=" operator through class-wide type
Date: Mon, 30 May 2022 08:30:11 +0000 (GMT)	[thread overview]
Message-ID: <20220530083011.BD35A3814FC4@sourceware.org> (raw)

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

commit r13-829-gfabf93dc1ae8268c416c1f2b77425922a6de046f
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Thu Apr 21 00:03:59 2022 +0200

    [Ada] Restore hiding of predefined "=" operator through class-wide type
    
    The previous change introduced a backward incompatibility in the handling
    of a user-defined "=" operator for a class-wide type of a tagged type: it
    would previously hide the predefined "=" operator of the tagged type in
    the private case, but it no longer does in this case, while it still does
    in the nonprivate case.
    
    This hiding is a non-portability, but is fundamentally what the compiler
    implements, instead of the RM rule which requires homographs.  The reason
    lies in the implementation of the "=" operator in GNAT: internally, there
    is not a "=" predefined operator for every nonlimited type, but instead
    there is a single, universal "=" predefined operator for all the nonlimited
    types.  The consequence is that the hiding rule implemented in GNAT for "="
    is effectively that a user-declared symmetrical "=" operator returning
    boolean hides the predefined "=" operator of any type that is covered by
    the user-declared operator.
    
    Whether it is desirable to implement the exact RM rule in GNAT is to be
    discussed, but existing code relies on the non-portability and would thus
    need to be changed.
    
    gcc/ada/
    
            * sem_ch6.adb (New_Overloaded_Entity): Deal specifically with the
            overriding of the "=" operator for tagged types.

Diff:
---
 gcc/ada/sem_ch6.adb | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index a5373583207..cb2ed7c5e45 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -12303,7 +12303,34 @@ package body Sem_Ch6 is
                            --  Work done in Override_Dispatching_Operation, so
                            --  nothing else needs to be done here.
 
-                           null;
+                           --  ??? Special case to keep supporting the hiding
+                           --  of the predefined "=" operator for a nonlimited
+                           --  tagged type by a user-defined "=" operator for
+                           --  its class-wide type when the type is private.
+
+                           if Chars (E) = Name_Op_Eq then
+                              declare
+                                 Typ : constant Entity_Id
+                                         := Etype (First_Entity (E));
+                                 H   : Entity_Id := Homonym (E);
+
+                              begin
+                                 while Present (H)
+                                   and then Scope (H) = Scope (E)
+                                 loop
+                                    if Is_User_Defined_Equality (H)
+                                       and then Is_Immediately_Visible (H)
+                                       and then Etype (First_Entity (H))
+                                                  = Class_Wide_Type (Typ)
+                                    then
+                                       Remove_Entity_And_Homonym (E);
+                                       exit;
+                                    end if;
+
+                                    H := Homonym (H);
+                                 end loop;
+                              end;
+                           end if;
                         end if;
 
                      else


                 reply	other threads:[~2022-05-30  8:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220530083011.BD35A3814FC4@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).