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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,68536605ede13a20 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.73.229 with SMTP id o5mr23465pbv.7.1324338421101; Mon, 19 Dec 2011 15:47:01 -0800 (PST) MIME-Version: 1.0 Path: lh20ni42119pbb.0!nntp.google.com!news2.google.com!goblin1!goblin.stu.neva.ru!news.tornevall.net!news.jacob-sparre.dk!pnx.dk!jacob-sparre.dk!ada-dk.org!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: GNAT - return by anonymous access Date: Mon, 19 Dec 2011 17:46:57 -0600 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <784c67eb-a542-41b0-b23d-fca1234e56b2@n10g2000vbg.googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1324338419 22331 69.95.181.76 (19 Dec 2011 23:46:59 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Mon, 19 Dec 2011 23:46:59 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Date: 2011-12-19T17:46:57-06:00 List-Id: "Simon Belmont" wrote in message news:784c67eb-a542-41b0-b23d-fca1234e56b2@n10g2000vbg.googlegroups.com... > > This ostensibly simple program prints strange results... ... > type test_type (p_obj : access Integer) is limited null record; ... > function get return test_type is > begin > return test_type'(p_obj => new Integer'(42)); > end get; You are creating a coextension here. The *language rules* for coextensions are full of bugs; we're fixing them virtually every ARG meeting. There is little hope for a compiler to get these right in the face of that, beyond which doing so is quite expensive. IMHO, any use of an allocator for an anonymous access type is asking for trouble. There is no way to free the memory for such things, and the lifetime can easily be extended in various ways, so if the compiler tries using a properly local pool for the allocator you end up with a dangling poiner. Moreover, they appear to promise something that they cannot deliver (heap-based allocation). Ada 2012 has a restriction No_Anonymous_Allocators; I recommend that all Ada programs include and obey this restriction. (Janus/Ada does this by default, because we never attempted to use the local pools that supposedly are required, and it is better to reject a program rather than implement it "wrong".) Randy.