This adds a missing test for the presence of a homograph when applying
the RM 8.4(10) clause about the visibility of operators, and removes
resolution code made obsolete by the change. There is also a fixlet
for a previously undetected ambiguity in the runtime.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_res.adb (Resolve_Eqyality_Op): Remove obsolete code.
(Resolve_Op_Not): Likewise.
* sem_type.adb (Disambiguate): Add missing test for RM 8.4(10).
* libgnat/s-dwalin.adb (Enable_Cache): Fix ambiguity.
(Symbolic_Address): Likewise.
gcc/testsuite/
* gnat.dg/equal7.adb: Add expected error messages (code is now
illegal).
diff --git a/gcc/ada/libgnat/s-dwalin.adb b/gcc/ada/libgnat/s-dwalin.adb
--- a/gcc/ada/libgnat/s-dwalin.adb
+++ b/gcc/ada/libgnat/s-dwalin.adb
@@ -1544,7 +1544,7 @@ package body System.Dwarf_Lines is
exit when Ar_Start = Null_Address and Ar_Len = 0;
Len := uint32 (Ar_Len);
- Start := uint32 (Ar_Start - C.Low);
+ Start := uint32 (Address'(Ar_Start - C.Low));
-- Search START in the array
@@ -1764,7 +1764,8 @@ package body System.Dwarf_Lines is
if C.Cache /= null then
declare
- Addr_Off : constant uint32 := uint32 (Addr - C.Low);
+ Addr_Off : constant uint32 := uint32 (Address'(Addr - C.Low));
+
First, Last, Mid : Natural;
begin
First := C.Cache'First;
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -8962,55 +8962,6 @@ package body Sem_Res is
Error_Msg_N ("?q?equality should be parenthesized here!", N);
end if;
- -- If the equality is overloaded and the operands have resolved
- -- properly, set the proper equality operator on the node. The
- -- current setting is the first one found during analysis, which
- -- is not necessarily the one to which the node has resolved.
-
- if Is_Overloaded (N) then
- declare
- I : Interp_Index;
- It : Interp;
-
- begin
- Get_First_Interp (N, I, It);
-
- -- If the equality is user-defined, the type of the operands
- -- matches that of the formals. For a predefined operator,
- -- it is the scope that matters, given that the predefined
- -- equality has Any_Type formals. In either case the result
- -- type (most often Boolean) must match the context. The scope
- -- is either that of the type, if there is a generated equality
- -- (when there is an equality for the component type), or else
- -- Standard otherwise.
-
- while Present (It.Typ) loop
- if Etype (It.Nam) = Typ
- and then
- (Etype (First_Entity (It.Nam)) = Etype (L)
- or else Scope (It.Nam) = Standard_Standard
- or else Scope (It.Nam) = Scope (T))
- then
- Set_Entity (N, It.Nam);
-
- Set_Is_Overloaded (N, False);
- exit;
- end if;
-
- Get_Next_Interp (I, It);
- end loop;
-
- -- If expansion is active and this is an inherited operation,
- -- replace it with its ancestor. This must not be done during
- -- preanalysis because the type may not be frozen yet, as when
- -- the context is a precondition or postcondition.
-
- if Present (Alias (Entity (N))) and then Expander_Active then
- Set_Entity (N, Alias (Entity (N)));
- end if;
- end;
- end if;
-
Check_Unset_Reference (L);
Check_Unset_Reference (R);
Generate_Operator_Reference (N, T);
@@ -10594,42 +10545,9 @@ package body Sem_Res is
end if;
-- Complete resolution and evaluation of NOT
- -- If argument is an equality and expected type is boolean, that
- -- expected type has no effect on resolution, and there are
- -- special rules for resolution of Eq, Neq in the presence of
- -- overloaded operands, so we directly call its resolution routines.
-
- declare
- Opnd : constant Node_Id := Right_Opnd (N);
- Op_Id : Entity_Id;
-
- begin
- if B_Typ = Standard_Boolean
- and then Nkind (Opnd) in N_Op_Eq | N_Op_Ne
- and then Is_Overloaded (Opnd)
- then
- Resolve_Equality_Op (Opnd, B_Typ);
- Op_Id := Entity (Opnd);
-
- if Ekind (Op_Id) = E_Function
- and then not Is_Intrinsic_Subprogram (Op_Id)
- then
- Rewrite_Operator_As_Call (Opnd, Op_Id);
- end if;
-
- if not Inside_A_Generic or else Is_Entity_Name (Opnd) then
- Freeze_Expression (Opnd);
- end if;
-
- Expand (Opnd);
-
- else
- Resolve (Opnd, B_Typ);
- end if;
-
- Check_Unset_Reference (Opnd);
- end;
+ Resolve (Right_Opnd (N), B_Typ);
+ Check_Unset_Reference (Right_Opnd (N));
Set_Etype (N, B_Typ);
Generate_Operator_Reference (N, B_Typ);
Eval_Op_Not (N);
diff --git a/gcc/ada/sem_type.adb b/gcc/ada/sem_type.adb
--- a/gcc/ada/sem_type.adb
+++ b/gcc/ada/sem_type.adb
@@ -2215,13 +2215,14 @@ package body Sem_Type is
return It2;
end if;
- -- An immediately visible operator hides a use-visible user-
- -- defined operation. This disambiguation cannot take place
- -- earlier because the visibility of the predefined operator
- -- can only be established when operand types are known.
+ -- RM 8.4(10): an immediately visible operator hides a use-visible
+ -- user-defined operation that is a homograph. This disambiguation
+ -- cannot take place earlier because visibility of the predefined
+ -- operator can only be established when operand types are known.
elsif Ekind (User_Subp) = E_Function
and then Ekind (Predef_Subp) = E_Operator
+ and then Operator_Matches_Spec (Predef_Subp, User_Subp)
and then Nkind (N) in N_Op
and then not Is_Overloaded (Right_Opnd (N))
and then
diff --git a/gcc/testsuite/gnat.dg/equal7.adb b/gcc/testsuite/gnat.dg/equal7.adb
--- a/gcc/testsuite/gnat.dg/equal7.adb
+++ b/gcc/testsuite/gnat.dg/equal7.adb
@@ -1,4 +1,4 @@
--- { dg-do run }
+-- { dg-do compile }
with Equal7_Pkg; use Equal7_Pkg;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
@@ -13,3 +13,11 @@ begin
null;
end if;
end;
+
+-- { dg-error "ambiguous expression \\(cannot resolve \"/=\"\\)" "" { target *-*-* } 9 }
+-- { dg-error "possible interpretation at a-strunb.ads:\\d+" "" { target *-*-* } 9 }
+-- { dg-error "possible interpretation in package Standard" "" { target *-*-* } 9 }
+
+-- { dg-error "ambiguous expression \\(cannot resolve \"=\"\\)" "" { target *-*-* } 12 }
+-- { dg-error "possible interpretation at a-strunb.ads:\\d+" "" { target *-*-* } 12 }
+-- { dg-error "possible interpretation in package Standard" "" { target *-*-* } 12 }