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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Type extension and discriminants Date: Sat, 11 Oct 2014 20:52:49 +0200 Organization: cbb software GmbH Message-ID: <1m1grtt4tjy6m$.2tgdf5cel9tn$.dlg@40tude.net> References: <8d6fe2a6-a8fa-441f-8b35-fc5a744359fb@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: ZB2Fb2q1fa4xpMpNKFqV6Q.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:22352 Date: 2014-10-11T20:52:49+02:00 List-Id: On Sat, 11 Oct 2014 10:45:55 -0700 (PDT), sbelmont700@gmail.com wrote: > On Friday, October 10, 2014 6:34:54 PM UTC-4, Randy Brukardt wrote: >> It would have helped a bit had you given an example. > > Thank you for your response. An example follows: > > package A is > type T1 (<>) is tagged limited private; > function T1_Ctor return T1; > private > type T1 (I_Ptr : access Integer) is tagged limited null record; > end A; > > > package body A is > function T1_Ctor return T1 is > begin > return (I_Ptr => null); > end T1_Ctor; > end A; > > with A; > package B is > type T2 (<>) is new A.T1 with private; > function T2_Ctor return T2; > private > type T2 is new A.T1 with null record; > end B; > > package body B is > function T2_Ctor return T2 is > begin > return T2'(A.T1_Ctor with null record); > end T2_Ctor; > > end B; Don't use this pattern, it simply does not work. Even without GNAT bugs. However all GNAT compilers I know have serious problems with more than one nested limited return. But if GNAT worked, this pattern will eventually hit you back. In short, limited return (constructing function) and limited aggregate are not suitable for construction of parent objects which private discriminants and components. As an alternative consider a child package to derive the type. Also consider using non-limited handles pointing to the reference counted limited private implementation objects. You can use the same interface type for both the handle type and the implementation type. The implementation of the interface for the handle type calls the implementation of the limited private implementation type after dereferencing (delegation). -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de