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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e859f774bbb3dfb3 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: another way to shoot yourself in the foot? Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <54157920-377a-441b-9b0b-f0c4f9ddffec@f36g2000hsa.googlegroups.com> <54435596-5e7f-4686-a2b7-1e22d7c4b186@p25g2000hsf.googlegroups.com> Date: Fri, 20 Jun 2008 12:26:28 +0200 Message-ID: NNTP-Posting-Date: 20 Jun 2008 12:26:28 CEST NNTP-Posting-Host: 1c43bb14.newsspool3.arcor-online.net X-Trace: DXC=9VRE1dUl`K;i6K;>iZ]763McF=Q^Z^V384Fo<]lROoR18kF7enW;^6ZC`4IXm65S@:3>?UZM<\dX0OZ2 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:777 Date: 2008-06-20T12:26:28+02:00 List-Id: On Fri, 20 Jun 2008 03:05:29 -0700 (PDT), christoph.grein@eurocopter.com wrote: >> --- Factory ads --- >> with Named; >> with Some; >> >> package Factory is >> � �function Create(class: String; name: String) return >> Named.Object'Class; >> end Factory; >> >> --- Factory.adb --- >> >> with Ada.Strings.Fixed; use Ada.Strings.Fixed; >> with Some; >> >> package body Factory is >> � �--- this one is ugly, but in sake of simplicity ... >> � �function Create(class: String; name: String) return >> Named.Object'Class is >> � �begin >> � � � if Index(class, "Some") /= 0 then >> � � � � �return Some.Create(name); >> � � � end if; >> � � � raise Program_Error with "Unknown class " & class; >> � �end; >> end Factory; > > Since Some.Object is limited, Factory must construct in place. The > normal return statement produces a copy (I guess there should be a > warning here - no compiler bug, since the RM has nothing to say about > warnings). Are you sure? Then it would be worse, a language design bug. Anyway a limited object cannot be copied, so it must be an error if an attempt is made. > So use the extended return statement as in Some.Create. It already does. Did you mean in Factory as well? Like this: function Create (class: String; name: String) return Named.Object'Class is begin if Index (class, "Some") /= 0 then return X : Named.Object'Class := Some.Create (name); end if; raise Program_Error with "Unknown class " & class; end; end Create; I bet it would not help. ------------------------- 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? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de