From: Steve Baird <ba...@adacore.com>

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).

Tested on x86_64-pc-linux-gnu, committed on master.

---
 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 406983995f3..50b3eee0dbe 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;
-- 
2.43.0

Reply via email to