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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Overloading operator =?utf-8?B?4oCcPeKAnQ==?= for anonymous access types? Date: Sat, 12 Jan 2019 09:50:14 +0000 Organization: A noiseless patient Spider Message-ID: References: <167dc83d-daac-49eb-ba79-48866ccde39d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="c5c9c60e67c5aad7af4ff0db5caff2dd"; logging-data="19082"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+QFI916tz/VJIyKywaelqVGOqM+g+FpgY=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (darwin) Cancel-Lock: sha1:ZL9IZAxN33pZV4cVnonsqtDKD8k= sha1:F5TP89elBrf6+eC5STU+1OJh5dY= Xref: reader01.eternal-september.org comp.lang.ada:55267 Date: 2019-01-12T09:50:14+00:00 List-Id: 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.