From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,ef86287aa487b07a,start X-Google-Attributes: gid103376,public From: Fran�oise & Herv� BITTEUR Subject: Pb with use of redefined "=" operator Date: 1998/11/03 Message-ID: <363F62F3.3FF7@club-internet.fr>#1/1 X-Deja-AN: 408036748 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=iso-8859-1 X-Trace: front5.grolier.fr 910123814 10373 195.36.149.178 (3 Nov 1998 20:10:14 GMT) Organization: Club-Internet (France) Mime-Version: 1.0 Reply-To: hbitteur@club-internet.fr NNTP-Posting-Date: 3 Nov 1998 20:10:14 GMT Newsgroups: comp.lang.ada Date: 1998-11-03T20:10:14+00:00 List-Id: I just run in a problem when combining : - Ada.Strings.Bounded where '=' operator is redefined, - A so far correct generic package (old Ada83 code) importing a private (non-limited) type. The problem is that any instantiation of the generic package will use the "predefined" equality operator provided with any non-limited type, rather than the specific definition related to Ada.Strings.Bounded. Which leads to unexpected results on some occasions. I have attached a very simplified example to illustrate the situation. An obvious fix is to modify the spec of the generic package to explicitly import a definition of '=' : with function "=" (L, R : in Item) return Boolean is <>; And the redefined version if any (or the predefined one if none) will then be used. But what puzzles me is that : 1/ No warning is raised by the compiler (how could it be otherwise ?) 2/ Correct code (till now) has silently got broken. Would you thus recommend that the line above ("with function "=" ...) be systematically added to each and every existing generic package using non-limited parameters ? Thanks for any advice. --Herv� BITTEUR hbitteur@club-internet.fr ------ Example - begin ----------------------------------------------------------- package Ints is type Int is new Integer; function "=" (Left, Right : Int) return Boolean; end Ints; with Ada.Text_IO; use Ada.Text_IO; package body Ints is function "=" (Left, Right : Int) return Boolean is begin Put_Line ("Ints. Function '=' is called"); return True; -- On purpose, to recognise the call. end "="; end Ints; generic type Item is private; Name : in String; with function "=" (L, R : in Item) return Boolean is <>;-- Added Line !!!!! package Gen_Test is procedure Foo (Left, Right : Item); end Gen_Test; with Ada.Text_IO; use Ada.Text_IO; package body Gen_Test is procedure Foo (Left, Right : Item) is begin if Left = Right then -- Which "=" operation ? Put_Line (Name & "Gen_Test. Items are equal"); else Put_Line (Name & "Gen_Test. Items are not equal"); end if; end Foo; end Gen_Test; with Ints; use Ints; with Gen_Test; with Ada.Text_IO; use Ada.Text_IO; procedure Test is package Int_Test is new Gen_Test (Int, "Int. "); package Integer_Test is new Gen_Test (Integer, "Integer. "); I : Int := 1; J : Int := 2; begin if I = J then Put_Line ("Test. Ints are equal"); else Put_Line ("Test. Ints are not equal"); end if; Int_Test.Foo (I, J); -- Ints."=" Integer_Test.Foo (Integer(I), Integer(J)); -- Predefined "=" end Test; ------ Example - end ------------------------------------------------------------- Here are the results using GNAT a/ without the added line: Ints. Function '=' is called Test. Ints are equal Int. Gen_Test. Items are not equal Integer. Gen_Test. Items are not equal b/ with the added line: Ints. Function '=' is called Test. Ints are equal Ints. Function '=' is called Int. Gen_Test. Items are equal Integer. Gen_Test. Items are not equal