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.5 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,ef86287aa487b07a X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Pb with use of redefined "=" operator Date: 1998/11/04 Message-ID: #1/1 X-Deja-AN: 408162920 Sender: matt@mheaney.ni.net References: <363F62F3.3FF7@club-internet.fr> NNTP-Posting-Date: Tue, 03 Nov 1998 19:17:13 PDT Newsgroups: comp.lang.ada Date: 1998-11-04T00:00:00+00:00 List-Id: Fran�oise & Herv� BITTEUR writes: > 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. This phenonmenon is called "reemergence of predefined operators," and it's one of Ada's trap doors. When you import a (non-tagged) type as a formal type, without also explicitly importing operators, then the predefined operators for the type are used, irrespective of whether the actual type has redefined them. > 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. ALWAYS import equality for any non-tagged formal type. In the data structure library I'm building, every private type is imported as generic type Item_Type is private; with function "=" (L, R : Item_Type) return Boolean is <>; ... package ACL.Stacks.Adapters is ... > But what puzzles me is that : > 1/ No warning is raised by the compiler (how could it be otherwise ?) Unfortunately, this is a "feature" of the language, not a flaw. > Would you thus recommend that the line above ("with function "=" ...) be > systematically added to each and every existing generic package using > non-limited parameters ? Yes. Always.