https://gcc.gnu.org/g:1189522245be51d435fcc6d205e690f086f12e46

commit r15-9793-g1189522245be51d435fcc6d205e690f086f12e46
Author: Steve Baird <ba...@adacore.com>
Date:   Fri Feb 7 12:29:46 2025 -0800

    ada: Incorrect unresolved operator name in an instantiation
    
    In some cases, a generic containing a use of a unary operator successfully
    compiles but the compiler incorrectly rejects the corresponding use in
    an instantiation.
    
    gcc/ada/ChangeLog:
    
            * sem_ch4.adb
            (Find_Unary_Types): Because we reanalyze names in an instance,
            we sometimes have to take steps to filter out extraneous name
            resolution candidates that happen to be visible at the point of the
            instance declaration. Remove some code that appears to have been
            written with this in mind. This is done for two reasons. First, the
            code sometimes doesn't work (possibly because the In_Instance test
            is not specific enough - it probably should be testing to see 
whether
            we are in an instance of the particular generic in which the result
            of calling Corresponding_Generic_Type was declared) and causes 
correct
            code to be rejected. Second, the code seems to no longer be 
necessary
            (possibly because of subsequent fixes in this area which are not
            specific to unary operators).

Diff:
---
 gcc/ada/sem_ch4.adb | 25 ++-----------------------
 1 file changed, 2 insertions(+), 23 deletions(-)

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index 406983995f3d..50b3eee0dbe5 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -7642,35 +7642,14 @@ package body Sem_Ch4 is
    begin
       if not Is_Overloaded (R) then
          if Is_Numeric_Type (Etype (R)) then
-
-            --  In an instance a generic actual may be a numeric type even if
-            --  the formal in the generic unit was not. In that case, the
-            --  predefined operator was not a possible interpretation in the
-            --  generic, and cannot be one in the instance, unless the operator
-            --  is an actual of an instance.
-
-            if In_Instance
-              and then
-                not Is_Numeric_Type (Corresponding_Generic_Type (Etype (R)))
-            then
-               null;
-            else
-               Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
-            end if;
+            Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
          end if;
 
       else
          Get_First_Interp (R, Index, It);
          while Present (It.Typ) loop
             if Is_Numeric_Type (It.Typ) then
-               if In_Instance
-                 and then
-                   not Is_Numeric_Type
-                     (Corresponding_Generic_Type (Etype (It.Typ)))
-               then
-                  null;
-
-               elsif Is_Effectively_Visible_Operator (N, Base_Type (It.Typ))
+               if Is_Effectively_Visible_Operator (N, Base_Type (It.Typ))
                then
                   Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
                end if;

Reply via email to