https://gcc.gnu.org/g:3b694271bec01ed971147a0f4cb68d8c9a7d0915

commit r15-6731-g3b694271bec01ed971147a0f4cb68d8c9a7d0915
Author: Eric Botcazou <ebotca...@adacore.com>
Date:   Sun Jan 5 17:34:41 2025 +0100

    ada: Fix missing detection of late equality operator returning subtype of 
Boolean
    
    In Ada 2012, the compiler fails to check that a primitive equality operator
    for an untagged record type must appear before the type is frozen, when the
    operator returns a subtype of Boolean.  This plugs the legality loophole but
    adds the debug switch -gnatd_q to go back to the previous state.
    
    gcc/ada/ChangeLog:
    
            PR ada/18765
            * debug.adb (d_q): Document new usage.
            * sem_ch6.adb (New_Overloaded_Entity): Apply the special processing
            to all equality operators whose base result type is Boolean, but do
            not enforce the new Ada 2012 freezing rule if the result type is a
            proper subtype of it and the -gnatd_q switch is specified.

Diff:
---
 gcc/ada/debug.adb   |  6 +++++-
 gcc/ada/sem_ch6.adb | 12 ++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/debug.adb b/gcc/ada/debug.adb
index 7b95fa87f02d..ac3ce41dcc51 100644
--- a/gcc/ada/debug.adb
+++ b/gcc/ada/debug.adb
@@ -154,7 +154,7 @@ package body Debug is
    --  d_n
    --  d_o
    --  d_p  Ignore assertion pragmas for elaboration
-   --  d_q
+   --  d_q  Do not enforce freezing for equality operator of boolean subtype
    --  d_r  Disable the use of the return slot in functions
    --  d_s  Stop elaboration checks on synchronous suspension
    --  d_t  In LLVM-based CCG, dump LLVM IR after transformations are done
@@ -999,6 +999,10 @@ package body Debug is
    --       semantics of invariants and postconditions in both the static and
    --       dynamic elaboration models.
 
+   --  d_q  The compiler does not enforce the new freezing rule introduced for
+   --       primitive equality operators in Ada 2012 when the operator returns
+   --       a subtype of Boolean.
+
    --  d_r  The compiler does not make use of the return slot in the expansion
    --       of functions returning a by-reference type. If this use is required
    --       for these functions to return on the primary stack, then they are
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index 49d83f8d5e06..80e0c9c634c3 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -12880,12 +12880,20 @@ package body Sem_Ch6 is
 
       <<Check_Inequality>>
          if Chars (S) = Name_Op_Eq
-           and then Etype (S) = Standard_Boolean
+           and then Base_Type (Etype (S)) = Standard_Boolean
            and then Present (Parent (S))
            and then not Is_Dispatching_Operation (S)
          then
             Make_Inequality_Operator (S);
-            Check_Untagged_Equality (S);
+
+            --  The freezing rule introduced in Ada 2012 was historically
+            --  not enforced for operators returning a subtype of Boolean.
+
+            if Etype (S) = Standard_Boolean
+              or else not Debug_Flag_Underscore_Q
+            then
+               Check_Untagged_Equality (S);
+            end if;
          end if;
    end New_Overloaded_Entity;

Reply via email to