comp.lang.ada
 help / color / mirror / Atom feed
From: onox <denkpadje@gmail.com>
Subject: Re: Limited type in generic package causes double free or corruption
Date: Wed, 28 Sep 2016 11:41:58 -0700 (PDT)
Date: 2016-09-28T11:41:58-07:00	[thread overview]
Message-ID: <bbd1a304-0349-4e79-a712-7a6ac36ec156@googlegroups.com> (raw)
In-Reply-To: <nsgqjt$5nr$1@dont-email.me>

On Wednesday, September 28, 2016 at 6:20:27 PM UTC+2, Jeffrey R. Carter wrote:
> What do you get if you rewrite this function as
> 
> function Get_Tree (Object : Thing) return Trees.Tree is
> begin
>    return Object.My_Tree;
> end Get_Tree;
> 
> ? The two forms should be equivalent.

Then I get (with -gnat2012) this:

>>> (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
>>> return by reference not permitted in Ada 2005

The error seems to refer to a paragraph in the RM that has been deleted in RM-2012. See http://www.adaic.org/resources/add_content/standards/12aarm/html/AA-6-5.html item 5.6/3 and 5.c/3.

5.6/3 refers to section 7.5 (http://www.adaic.org/resources/add_content/standards/12aarm/html/AA-7-5.html). If I understand 2.9/3 in section 7.5 correctly, my current code should be allowed (which may explain why it does compile in GNAT 2016 according to Anh Vo).

Anyway, Get_Tree is simply meant as a getter. In my non-example code, the tree is constructed in the extended return in Load_Thing.

If Tree is tagged (which it is), doesn't that mean Ada uses copy-by-reference instead of copy-by-value. Or am I mixing things up here?

If it doesn't, then the Tree record is simply copied, and because Ada.Containers.Vectors is controlled, it's basically just a shallow copy?


  reply	other threads:[~2016-09-28 18:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-28 13:25 Limited type in generic package causes double free or corruption onox
2016-09-28 16:06 ` Dmitry A. Kazakov
2016-09-28 16:20 ` Jeffrey R. Carter
2016-09-28 18:41   ` onox [this message]
2016-09-28 19:51     ` Jeffrey R. Carter
2016-09-29  8:12     ` Alejandro R. Mosteo
2016-09-28 17:27 ` Anh Vo
2016-09-28 17:34 ` AdaMagica
2016-09-28 21:42   ` Randy Brukardt
replies disabled

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