comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Pb with use of redefined "=" operator
Date: 1998/11/04
Date: 1998-11-04T00:00:00+00:00	[thread overview]
Message-ID: <m3zpa860yd.fsf@mheaney.ni.net> (raw)
In-Reply-To: 363F62F3.3FF7@club-internet.fr

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1834 bytes --]

Fran�oise & Herv� BITTEUR <hbitteur@club-internet.fr> 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.




  reply	other threads:[~1998-11-04  0:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-11-03  0:00 Pb with use of redefined "=" operator Fran�oise & Herv� BITTEUR
1998-11-04  0:00 ` Matthew Heaney [this message]
1998-11-04  0:00   ` Mats Weber
1998-11-05  0:00     ` Matthew Heaney
1998-11-05  0:00       ` dewarr
1998-11-05  0:00         ` Matthew Heaney
1998-11-06  0:00           ` dewarr
1998-11-09  0:00             ` Robert A Duff
1998-11-10  0:00               ` dennison
1998-11-10  0:00                 ` Robert A Duff
1998-11-05  0:00       ` Mats Weber
1998-11-05  0:00         ` Matthew Heaney
1998-11-09  0:00           ` Robert A Duff
1998-11-09  0:00             ` Brian Rogoff
1998-11-10  0:00               ` Robert A Duff
1998-11-10  0:00             ` Robert I. Eachus
1998-11-04  0:00 ` dewarr
1998-11-04  0:00   ` Tucker Taft
1998-11-04  0:00 ` Mats Weber
1998-11-04  0:00   ` Fran�oise & Herv� BITTEUR
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox