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,f8a440310f7f2e02 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!newspeer.monmouth.com!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Extended return question Date: Thu, 10 Jul 2008 20:43:09 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <69940bd4-74f7-4b00-93d6-482c7394fcef@34g2000hsf.googlegroups.com> <1pdpniur1w9sq$.1a9h7prydviae$.dlg@40tude.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1215736989 31993 192.74.137.71 (11 Jul 2008 00:43:09 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 11 Jul 2008 00:43:09 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:QqcrFBKdFf5bhRetgIm/tvUDO0I= Xref: g2news1.google.com comp.lang.ada:1103 Date: 2008-07-10T20:43:09-04:00 List-Id: "Dmitry A. Kazakov" writes: > On Thu, 10 Jul 2008 08:19:41 -0700 (PDT), Adam Beneschan wrote: > >> The upshot of this AI is, I think, that (1) the object >> being worked on for an extended return is *not* an "alias" for the >> object being created, even for a limited type, and (2) although >> limited types aren't supposed to be copied, this is true only in an >> Ada semantic sense, and implementations are allowed to do any block- >> copies they wish as long as they get the Ada semantics right. > > Right, and the position 1 is inconsistent with the notion of limited type. > A "backdoor" 2 does not save it as the following example illustrates: I don't see any problem here. The "notion of limited type" is "do not copy". In the example below, X is created, then destroyed, then another X is created, and that becomes the result. No copying. > with Ada.Finalization; > with Ada.Text_IO; use Ada.Text_IO; > > procedure Test_Return is > package Test is > type T is > new Ada.Finalization.Limited_Controlled with null record; > overriding > procedure Finalize (X : in out T); > overriding > procedure Initialize (X : in out T); > function Create return T; > end Test; > > package body Test is > procedure Finalize (X : in out T) is > begin > Put_Line ("Finalized"); > end Finalize; > procedure Initialize (X : in out T) is > begin > Put_Line ("Initialized"); > end Initialize; > function Create return T is > begin > return X : T do > raise Constraint_Error; > end return; > exception > when Constraint_Error => > return X : T; > end Create; > end Test; > > use Test; > X : T := Create; > begin > null; > end Test_Return; > > The output should be: > > Initialized > Finalized > Initialized > Finalized Right. > This is a case when *a* limited object is initialized and finalized twice, > which is semantically inconsistent. No, X is initialized and finalized, then a different X is initialized, which becomes a still-different X, which is then finalized. I don't see how that's "semantically inconsistent". > OK, Initialize is not a constructor. But we could rewrite the above so that > Create would call itself multiple times over the "same" X before it would > finally "return" X! - Bob