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,f34f2cf6eacd2bc8 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.30.202 with SMTP id u10mr3573276pbh.1.1319296608008; Sat, 22 Oct 2011 08:16:48 -0700 (PDT) Path: d5ni43758pbc.0!nntp.google.com!news1.google.com!newsfeed2.dallas1.level3.net!news.level3.com!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Private constant of tagged limited controlled type Date: Sat, 22 Oct 2011 11:16:47 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 X-Trace: pcls6.std.com 1319296607 12752 192.74.137.71 (22 Oct 2011 15:16:47 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sat, 22 Oct 2011 15:16:47 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:jNlgV10gEp9nBxgZZxhMBXqGxQY= Xref: news1.google.com comp.lang.ada:18669 Content-Type: text/plain; charset=us-ascii Date: 2011-10-22T11:16:47-04:00 List-Id: Jeffrey Carter writes: > On 10/21/2011 11:14 PM, Malaise wrote: >> The following complains that "initialization of limited object >> requires aggregate or function call": > > Right. > >> with Ada.Finalization; >> package Pack is >> type T is tagged limited private; >> C : constant T; >> private >> type T is new Ada.Finalization.Limited_Controlled with record >> I : Integer := 0; >> end record; >> V : T; >> C : constant T := V; That's illegal, because you're trying to copy a limited object. What if T had a self-referential component? If the above were allowed, C.Self would incorrectly point to V, not C. What if T contained a protected object? It makes no sense to copy locks. >> end Pack; >> Aggregate seems impossible because Limited_Controlled is abstract and >> anyway T is very complex in fact. > > I suggest you read ARM 4.3.1 and 4.3.2. You can write an aggregate of the form > > (Ada.Finalization.Limited_Controlled with others => <>) Right, or: C : constant T := (Ada.Finalization.Limited_Controlled with I => 123) >> A function (returning tagged type) has to be visible and anyway cannot >> return V (in Ada 2005). > > This is an unusual claim. The extended return statement was introduced > specifically for returning limited types from a function. You ought to > read ARM 6.5. You could write > > return X : T; Right. Or it could say return (Ada.Finalization.Limited_Controlled with others => <>); But the comment, "cannot return V" is correct -- no matter whether V is local or global. > to return a value of T with all components set to their default values. I also suggest reading this: http://www.adacore.com/2007/09/24/ada-gem-10/ and also the following 2 gems, which I wrote to explain how limited types work in Ada 2005. - Bob