comp.lang.ada
 help / color / mirror / Atom feed
From: kst@alsys.com (Keith Thompson)
Subject: Re: Ada.strings.bounded problems?
Date: Thu, 19 Jan 1995 01:36:14 GMT
Date: 1995-01-19T01:36:14+00:00	[thread overview]
Message-ID: <D2MpsE.HyJ@thomsoft.com> (raw)
In-Reply-To: Mats.Weber-1701951908250001@mlma11.matrix.ch

In <Mats.Weber-1701951908250001@mlma11.matrix.ch> Mats.Weber@matrix.ch (Mats Weber) writes:
> In article <3fduto$ta7@watnews1.watson.ibm.com>, ncohen@watson.ibm.com wrote:
> > Ada 95 allows predefined equality to be overridden, even for nonlimited
> > types, so the declaration of a type Bounded_String with a discriminant
> > specifying the maximum length should be accompanied by the declaration
> > for the following function: 
> > 
> >    function "=" (Left, Right: Bounded_String) return Boolean is ...
> 
> This helps some, but still has severe problems. For instance if I write
> 
>    type Pair is
>       record
>          First,
>          Second : Bounded_String;
>       end record;
> 
> then "=" is broken for Pair. This situation is very bad because overriding
> "=" on Bounded_String gives the programmer the feeling that the problem is
> solved, but it reappears whenever a Bounded_String is used as a component
> of a composite type.

Interesting.  This is a potential problem that didn't occur (as seriously)
in Ada 83.  Since Ada 83 only allowed "=" to be overloaded for limited
types, and a type with a limited component is also limited, a type with
a subcomponent that has a user-defined "=" operator generally wouldn't
have its own "=" operator unless the user explicitly defined one (unless
you used the generic trick).

In Ada 95, it's very easy to have a case like the above where the
user-defined "=" operator for a subcomponent is bypassed.  Section II-6.3
of the Rationale, which discusses overloading of "=" and "/=", doesn't
mention this problem.  Quite possibly it was simply overlooked.

It's obviously too late to fix this in the language by requiring
predefined "=" to invoke user-defined "=" for subcomponents.

I suggest that Ada 95 compilers should issue a warning for a type
whose predefined "=" operator bypasses a user-defined "=" operator
for a subcomponent.  Determining exactly when to issue such a warning
may be difficult ("=" can be declared to return a type other than
Standard.Boolean, the left and right operands can be different types,
"=" and "/=" can be overloaded separately in some circumstances, the
declaration for "=" needn't be in the same scope as the operand type(s),
etc.), but catching the most common cases shouldn't be difficult.

-- 
Keith Thompson (The_Other_Keith)  kst@thomsoft.com (kst@alsys.com still works)
TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
When you're a nail, every problem looks like a hammer.



  parent reply	other threads:[~1995-01-19  1:36 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <TARJEIJ.95Jan11183331@ulrik.uio.no>
1995-01-12 14:24 ` Ada.strings.bounded problems? Robert Dewar
1995-01-12 15:59 ` Norman H. Cohen
1995-01-13 19:33   ` Mats Weber
     [not found] ` <EACHUS.95Jan11170317@spectre.mitre.org>
1995-01-12 18:10   ` Robert Dewar
     [not found] ` <D29L78.J9@nntpa.cb.att.com>
1995-01-12 18:16   ` Norman H. Cohen
1995-01-13 10:52     ` Tarjei Jensen
1995-01-13 19:29     ` Mats Weber
     [not found]       ` <3fduto$ta7@watnews1.watson.ibm.com>
     [not found]         ` <Mats.Weber-1701951908250001@mlma11.matrix.ch>
1995-01-18 14:27           ` Norman H. Cohen
1995-01-19 16:49             ` Mats Weber
1995-01-21  5:28               ` Robert Dewar
     [not found]             ` <1995Jan19.124412@lglsun.epfl.ch>
1995-01-19 21:59               ` Norman H. Cohen
1995-01-23 15:56                 ` Mats Weber
1995-01-24 18:49                   ` Robert A Duff
1995-01-24 19:24                   ` Robert Dewar
1995-01-25 17:26                     ` Norman H. Cohen
     [not found]                     ` <Mats.Weber-2701952307410001@mlma11.matrix.ch>
1995-01-30 14:15                       ` David Emery
1995-02-01 14:02                         ` William Brennan
1995-02-01 14:28                           ` William Brennan
1995-02-01 20:46                           ` Robert Firth
     [not found]                             ` <3gr5b4$1eq2@info4.rus.uni-stuttgart.de>
     [not found]                               ` <D3H6qD.AD6@inmet.camb.inmet.com>
1995-02-07 20:22                                 ` Norman H. Cohen
1995-02-11 15:58                                   ` David Weller
1995-02-01 21:48                           ` Mark A Biggar
     [not found]                           ` <3grvi1$jvm@gnat.cs.nyu.edu>
1995-02-08 15:22                             ` Passive tasks (was: bounded strings) Schilling J.
1995-02-10  1:51                               ` Robert Dewar
1995-01-20 17:00               ` Ada.strings.bounded problems? Robert Dewar
1995-01-18 16:23           ` Cyrille Comar
1995-01-18 17:48           ` Robert Dewar
1995-01-19  1:36           ` Keith Thompson [this message]
1995-01-19 17:53             ` Jacob Sparre Andersen
1995-01-20 11:12               ` Robb Nebbe
1995-01-20 16:03                 ` Magnus Kempe
1995-01-21 18:57                   ` Robert Dewar
1995-01-23 13:37                     ` Robb Nebbe
1995-01-24 14:38                       ` Robert Dewar
1995-01-24 19:24                       ` Tucker Taft
1995-01-25 10:25                         ` Robb Nebbe
     [not found]                         ` <Mats.Weber-2701952308000001@mlma11.matrix.ch>
1995-01-29  5:29                           ` Robert Dewar
     [not found]           ` <1995Jan18.164836.2222@nbivax.nbi.dk>
1995-01-22 18:05             ` Tucker Taft
1995-01-12 22:17   ` Robert Dewar
     [not found]     ` <D2D8DC.JvM@nntpa.cb.att.com>
     [not found]       ` <3fja22$fab@source.asset.com>
1995-01-18 18:02         ` Norman H. Cohen
1995-01-20  5:12         ` Robert Dewar
     [not found]   ` <D2J8H0.DMu@aplcenmp.apl.jhu.edu>
1995-01-18  5:01     ` Robert Dewar
1995-01-22 18:09     ` Tucker Taft
replies disabled

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