comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Overloading operator “=” for anonymous access types?
Date: Sat, 12 Jan 2019 09:50:14 +0000
Date: 2019-01-12T09:50:14+00:00	[thread overview]
Message-ID: <lymuo619yh.fsf@pushface.org> (raw)
In-Reply-To: 167dc83d-daac-49eb-ba79-48866ccde39d@googlegroups.com

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.

  reply	other threads:[~2019-01-12  9:50 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 [this message]
2019-01-12 14:01   ` Simon Wright
2019-01-12 15:15   ` daicrkk
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