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!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Limited type in generic package causes double free or corruption Date: Wed, 28 Sep 2016 12:51:04 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <374b0d79-541d-44d2-886e-dd41f8815914@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Wed, 28 Sep 2016 19:51:01 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="6df4b173985f7c5c043cea362c370ff7"; logging-data="24421"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mgFKmuSFaW9hJEFSAOP+ScnjxKHxxA60=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 In-Reply-To: Cancel-Lock: sha1:kTtGG5nuQISGMQMS+PWL3rPvIH8= Xref: news.eternal-september.org comp.lang.ada:31927 Date: 2016-09-28T12:51:04-07:00 List-Id: On 09/28/2016 11:41 AM, onox wrote: > > 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. I expected an error, though this is not a very useful message. The referenced paragraph in the ARM for ISO/IEC 8652:2007 reads, "If the result subtype of the function is limited, then the expression of the return statement (if any) shall be an aggregate, a function call (or equivalent use of an operator), or a qualified_expression or parenthesized expression whose operand is one of these." > 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). No, 2.9 says that the expression of an expression function that returns a limited type must be something allowed by 2.1: basically an aggregate or function call. Your expression function's expression is an object, which is not allowed. I think you have discovered a GNAT error in compiling expression functions that return a limited type. > 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? You are confused, though I'm not sure about what. Since Tree is limited, it cannot be copied. -- Jeff Carter "Brave Sir Robin ran away." Monty Python and the Holy Grail 59