comp.lang.ada
 help / color / mirror / Atom feed
From: daicrkk@googlemail.com
Subject: Re: Overloading operator “=” for anonymous access types?
Date: Sat, 12 Jan 2019 07:15:38 -0800 (PST)
Date: 2019-01-12T07:15:38-08:00	[thread overview]
Message-ID: <0c56d9f4-8861-4c74-b170-a973e3789b08@googlegroups.com> (raw)
In-Reply-To: <lymuo619yh.fsf@pushface.org>

On Saturday, January 12, 2019 at 10:50:17 AM UTC+1, Simon Wright wrote:
> daicrkk@googlemail.com writes:
> 
> > I am working my way through Barnes' excellent Ada book. This is a code
> > sample for deep comparison of linked lists from section 11.7:
> >
> >
> > type Cell is
> >   record
> >     Next: access Cell;
> >     Value: Integer;
> >   end record;
> >
> > function "=" (L, R: access Cell) return Boolean is
> > begin
> >   if L = null or R = null then    -- universal =
> >     return L = R;                 -- universal = (Line A)
> >   elsif L.Value = R.Value then
> >     return L.Next = R.Next;       -- recurses OK (Line B)
> >   else
> >     return False;
> >   end if;
> > end "=";
> [...]
> > I did my best to find anything in the AARM, especially section 4.5.2,
> > but could not make any sense of it.
> 
> Given ARM 4.5.2(9.1 ff),
> 
>    At least one of the operands of an equality operator for
>    universal_access shall be of a specific anonymous access type. Unless
>    the predefined equality operator is identified using an expanded name
>    with prefix denoting the package Standard, neither operand shall be
>    of an access-to-object type whose designated type is D or D'Class,
>    where D has a user-defined primitive equality operator such that:
> 
>    * its result type is Boolean;
> 
>    * it is declared immediately within the same declaration list as D or
>      any partial or incomplete view of D; and
> 
>    * at least one of its operands is an access parameter with designated
>      type D.
> 
> I'm not at all clear why the example code is legal, or why it would be
> legal to call it; since 'access Cell' appears to match "neither operand
> shall be of an access-to-object type whose designated type is D or
> D'Class, where D has a user-defined primitive equality operator ..."
> 
> Might explain why compiling this example with GNAT (CE 2018) results in
> stack overflow.

I second that. Access Cell is an access-to-object type whose designated type is Cell (check), Cell has a user-defined primitive equality operator (check) such that its result type is Boolean (check), it is declared immediately within the same declaration list as Cell (check), at least one of its operands is an access parameter with designated type Cell (both operands are, check).
According to 4.5.2, universal_access "=" should never be allowed to kick in at all here, not even with "L = null". Or am I missing something?

  parent reply	other threads:[~2019-01-12 15:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-11 21:46 Overloading operator “=” for anonymous access types? daicrkk
2019-01-12  9:50 ` Simon Wright
2019-01-12 14:01   ` Simon Wright
2019-01-12 15:15   ` daicrkk [this message]
2019-01-14 23:08     ` Overloading operator "=" " Randy Brukardt
2019-01-15  0:34       ` Shark8
2019-01-15  8:38       ` Dmitry A. Kazakov
2019-01-15 21:00         ` Randy Brukardt
2019-01-16 15:42           ` Dmitry A. Kazakov
2019-01-15  8:51       ` daicrkk
2019-01-15 11:15         ` Simon Wright
2019-01-17  3:20       ` Jere
2019-01-17  8:23         ` Dmitry A. Kazakov
2019-01-17 22:22         ` Randy Brukardt
2019-01-18 10:17           ` Dmitry A. Kazakov
2019-01-18 13:27           ` Jere
2019-01-18 13:42             ` Dmitry A. Kazakov
replies disabled

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