Patchwork [Ada] Warnings on operator renamings

login
register
mail settings
Submitter Arnaud Charlet
Date Oct. 26, 2010, 1 p.m.
Message ID <20101026130017.GA22142@adacore.com>
Download mbox | patch
Permalink /patch/69245/
State New
Headers show

Comments

Arnaud Charlet - Oct. 26, 2010, 1 p.m.
The compiler warns if an operator in an renaming declaration renames an operator
with a different name. This patch extends the warning to the case where the
renamed operator is a predefined one.
Compiling oprename.ads must yield:

  oprename.ads:2:49: warning: "-" is being renamed as a different operator

---
package oprename is
   function "+" (X, Y : Integer) return Integer renames "-";
end oprename;

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-10-26  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch8.adb (Analyze_Subprogram_Renaming): Improve warning when an
	operator renames another one with a different name.

Patch

Index: sem_ch8.adb
===================================================================
--- sem_ch8.adb	(revision 165946)
+++ sem_ch8.adb	(working copy)
@@ -2480,16 +2480,19 @@  package body Sem_Ch8 is
 
       --  A useful warning, suggested by Ada Bug Finder (Ada-Europe 2005)
       --  is to warn if an operator is being renamed as a different operator.
+      --  If the operator is predefined, examine the kind of the entity, not
+      --  the abbreviated declaration in Standard.
 
       if Comes_From_Source (N)
         and then Present (Old_S)
-        and then Nkind (Old_S) = N_Defining_Operator_Symbol
+        and then
+          (Nkind (Old_S) = N_Defining_Operator_Symbol
+            or else Ekind (Old_S) = E_Operator)
         and then Nkind (New_S) = N_Defining_Operator_Symbol
         and then Chars (Old_S) /= Chars (New_S)
       then
          Error_Msg_NE
-           ("?& is being renamed as a different operator",
-             New_S, Old_S);
+           ("?& is being renamed as a different operator", N, Old_S);
       end if;
 
       --  Check for renaming of obsolescent subprogram