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,e859f774bbb3dfb3 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!t12g2000prg.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: another way to shoot yourself in the foot? Date: Fri, 20 Jun 2008 09:12:16 -0700 (PDT) Organization: http://groups.google.com Message-ID: <25e91ad7-74ce-4b86-b067-8bde57f34380@t12g2000prg.googlegroups.com> References: <54157920-377a-441b-9b0b-f0c4f9ddffec@f36g2000hsa.googlegroups.com> <54435596-5e7f-4686-a2b7-1e22d7c4b186@p25g2000hsf.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1213978336 13054 127.0.0.1 (20 Jun 2008 16:12:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 20 Jun 2008 16:12:16 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: t12g2000prg.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:785 Date: 2008-06-20T09:12:16-07:00 List-Id: On Jun 20, 3:26 am, "Dmitry A. Kazakov" wrote: > Honestly I have no idea how it is managed on the language level. A limited > interface can be implemented by a non-limited object. Thus from the > declaration of a factory function, returning a class-wide of some limited > interface, the compiler cannot decide whether the result should be in-place > or not. Therefore, IMO, it must consider the worst case, i.e. an in-place > "return". > > Language lawyers? Interesting question. I may have to look through AI's to see if this case was discussed at all. However, at first glance, when I look at the wording in 7.5, it talks about the type of the *expression* that you're using, not the expected type of the thing you're using it for. This is true in 7.5(2.1), where it puts restrictions on where expressions of a limited type may be used, and in 7.5(8.1), where it says that certain expressions of a limited type (i.e. aggregates and function calls) must be built in place. So off the top of my head, I think that if you say type Int1 is limited interface; type Rec is new Int1 with record -- not limited! ... function Func (...) returns Rec is ...; Obj : Int1'Class := Func(...); Since the call to Func is an expression of type Rec, which is not limited, there's no build-in-place requirement; the fact that Obj's type is the classwide type for a limited interface isn't relevant to that rule. The compiler knows what type Func is, so there's no "assume-the-worst" issue. If, instead, we had said function Func2 (...) returns Int1'Class is ...; Obj : Int1'Class := Func2(...); Now Func2 needs to be called in such a way that it will build the result in place; following my previous post, this essentially means passing the address of Obj to Func2. But whether Func2 passes this address on to other functions depends on what the "return" statements in Func2 look like, and the compiler will make the appropriate decision at that point. So I don't think there's any "assume-the- worst" issue here either. -- Adam