comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: GNAT - return by anonymous access
Date: Mon, 19 Dec 2011 17:46:57 -0600
Date: 2011-12-19T17:46:57-06:00	[thread overview]
Message-ID: <jcoidj$lpr$1@munin.nbi.dk> (raw)
In-Reply-To: 784c67eb-a542-41b0-b23d-fca1234e56b2@n10g2000vbg.googlegroups.com

"Simon Belmont" <sbelmont700@gmail.com> 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.





  parent reply	other threads:[~2011-12-19 23:47 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-17 19:17 GNAT - return by anonymous access Simon Belmont
2011-12-17 19:51 ` Simon Wright
2011-12-18  9:08 ` Georg Bauhaus
2011-12-19 23:46 ` Randy Brukardt [this message]
2011-12-20  0:14   ` Shark8
2011-12-20 23:18     ` Randy Brukardt
2011-12-21  0:44       ` Simon Belmont
2011-12-21  7:29         ` AdaMagica
2011-12-21 11:05           ` Georg Bauhaus
2011-12-21 11:43             ` AdaMagica
2011-12-21 12:05               ` Georg Bauhaus
2011-12-22  0:33                 ` Randy Brukardt
2011-12-22  0:33           ` Simon Belmont
2011-12-22  7:11             ` Adam Beneschan
2011-12-22 22:11               ` Simon Belmont
2011-12-23  0:56                 ` Randy Brukardt
2011-12-23 13:20                   ` Simon Belmont
2011-12-27 23:51                     ` Randy Brukardt
2011-12-20 23:53 ` anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox