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-1428] [Ada] Give missing error on ambiguous operand of equality operator
Date: Mon,  4 Jul 2022 07:50:22 +0000 (GMT)	[thread overview]
Message-ID: <20220704075022.9A66E3851C02@sourceware.org> (raw)

https://gcc.gnu.org/g:4030e83c276c63700b62c3cebd49097f83cf6288

commit r13-1428-g4030e83c276c63700b62c3cebd49097f83cf6288
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Tue May 24 20:38:01 2022 +0200

    [Ada] Give missing error on ambiguous operand of equality operator
    
    When the code responsible for giving errors on ambiguous operands of
    comparison and equality operators was moved from the 1st phase (analysis)
    to the 2nd phase (resolution) of semantic processing, it was incorrectly
    restricted to the operator case, which was valid during the 1st phase but
    is not during the 2nd phase.
    
    gcc/ada/
    
            * sem_res.adb (Resolve_Comparison_Op): Deal with ambiguous operands
            in all cases.
            (Resolve_Equality_Op): Likewise, except for the case of the implicit
            inequality operator created for a user-defined operator that is not
            an intrinsic subprogram.

Diff:
---
 gcc/ada/sem_res.adb | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 7d595eb23e8..fd1615d9a25 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -7539,9 +7539,7 @@ package body Sem_Res is
       if T = Any_Type then
          --  Deal with explicit ambiguity of operands
 
-         if Ekind (Entity (N)) = E_Operator
-           and then (Is_Overloaded (L) or else Is_Overloaded (R))
-         then
+         if Is_Overloaded (L) or else Is_Overloaded (R) then
             Ambiguous_Operands (N);
          end if;
 
@@ -8563,6 +8561,16 @@ package body Sem_Res is
       L : constant Node_Id := Left_Opnd (N);
       R : constant Node_Id := Right_Opnd (N);
 
+      Implicit_NE_For_User_Defined_Operator : constant Boolean :=
+        Nkind (N) = N_Op_Ne
+          and then Ekind (Entity (N)) = E_Function
+          and then not Comes_From_Source (Entity (N))
+          and then not
+            Is_Intrinsic_Subprogram (Corresponding_Equality (Entity (N)));
+      --  Whether this is a call to the implicit inequality operator created
+      --  for a user-defined operator that is not an intrinsic subprogram, in
+      --  which case we need to skip some processing.
+
       T : Entity_Id := Find_Unique_Type (L, R);
 
       procedure Check_Access_Attribute (N : Node_Id);
@@ -8833,9 +8841,12 @@ package body Sem_Res is
       Generate_Reference (T, N, ' ');
 
       if T = Any_Type then
-         --  Deal with explicit ambiguity of operands
+         --  Deal with explicit ambiguity of operands, unless this is a call
+         --  to the implicit inequality operator created for a user-defined
+         --  operator that is not an intrinsic subprogram, since the common
+         --  resolution of operands done here does not apply to it.
 
-         if Ekind (Entity (N)) = E_Operator
+         if not Implicit_NE_For_User_Defined_Operator
            and then (Is_Overloaded (L) or else Is_Overloaded (R))
          then
             Ambiguous_Operands (N);
@@ -9009,17 +9020,11 @@ package body Sem_Res is
          Generate_Operator_Reference (N, T);
          Check_Low_Bound_Tested (N);
 
-         --  If this is an inequality, it may be the implicit inequality
-         --  created for a user-defined operation, in which case the corres-
-         --  ponding equality operation is not intrinsic, and the operation
-         --  cannot be constant-folded. Else fold.
+         --  Unless this is a call to the implicit inequality operator created
+         --  for a user-defined operator that is not an intrinsic subprogram,
+         --  try to fold the operation.
 
-         if Nkind (N) = N_Op_Eq
-           or else Comes_From_Source (Entity (N))
-           or else Ekind (Entity (N)) = E_Operator
-           or else
-             Is_Intrinsic_Subprogram (Corresponding_Equality (Entity (N)))
-         then
+         if not Implicit_NE_For_User_Defined_Operator then
             Analyze_Dimension (N);
             Eval_Relational_Op (N);


                 reply	other threads:[~2022-07-04  7:50 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=20220704075022.9A66E3851C02@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).