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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a02:9912:: with SMTP id r18mr4221904jaj.2.1547306138689; Sat, 12 Jan 2019 07:15:38 -0800 (PST) X-Received: by 2002:a9d:6f14:: with SMTP id n20mr85245otq.2.1547306138578; Sat, 12 Jan 2019 07:15:38 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.166.216.MISMATCH!q69no194408itb.0!news-out.google.com!v71ni274ita.0!nntp.google.com!k10no194493itk.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 12 Jan 2019 07:15:38 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2003:da:3712:9e01:d250:99ff:fe54:d2d2; posting-account=UO7etwoAAAD8dZ9XMqp9pq9hGTWlWnZb NNTP-Posting-Host: 2003:da:3712:9e01:d250:99ff:fe54:d2d2 References: <167dc83d-daac-49eb-ba79-48866ccde39d@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0c56d9f4-8861-4c74-b170-a973e3789b08@googlegroups.com> Subject: =?UTF-8?Q?Re=3A_Overloading_operator_=E2=80=9C=3D=E2=80=9D_for_anonymous_acces?= =?UTF-8?Q?s_types=3F?= From: daicrkk@googlemail.com Injection-Date: Sat, 12 Jan 2019 15:15:38 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:55272 Date: 2019-01-12T07:15:38-08:00 List-Id: On Saturday, January 12, 2019 at 10:50:17 AM UTC+1, Simon Wright wrote: > daicrkk@googlemail.com writes: >=20 > > 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 "=3D" (L, R: access Cell) return Boolean is > > begin > > if L =3D null or R =3D null then -- universal =3D > > return L =3D R; -- universal =3D (Line A) > > elsif L.Value =3D R.Value then > > return L.Next =3D R.Next; -- recurses OK (Line B) > > else > > return False; > > end if; > > end "=3D"; > [...] > > I did my best to find anything in the AARM, especially section 4.5.2, > > but could not make any sense of it. >=20 > Given ARM 4.5.2(9.1 ff), >=20 > 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: >=20 > * its result type is Boolean; >=20 > * it is declared immediately within the same declaration list as D or > any partial or incomplete view of D; and >=20 > * at least one of its operands is an access parameter with designated > type D. >=20 > 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 ..." >=20 > 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 typ= e is Cell (check), Cell has a user-defined primitive equality operator (che= ck) such that its result type is Boolean (check), it is declared immediatel= y within the same declaration list as Cell (check), at least one of its ope= rands is an access parameter with designated type Cell (both operands are, = check). According to 4.5.2, universal_access "=3D" should never be allowed to kick = in at all here, not even with "L =3D null". Or am I missing something?