comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Extended return question
Date: Thu, 10 Jul 2008 20:36:51 +0200
Date: 2008-07-10T20:36:53+02:00	[thread overview]
Message-ID: <1pdpniur1w9sq$.1a9h7prydviae$.dlg@40tude.net> (raw)
In-Reply-To: 69940bd4-74f7-4b00-93d6-482c7394fcef@34g2000hsf.googlegroups.com

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:

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

This is a case when *a* limited object is initialized and finalized twice,
which is 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!

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2008-07-10 18:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-10  2:11 Extended return question Dale Stanbrough
2008-07-10  7:18 ` Georg Bauhaus
2008-07-10  7:32   ` Dale Stanbrough
2008-07-10 15:24     ` Adam Beneschan
2008-07-10 23:56       ` Dale Stanbrough
2008-07-10 23:20     ` Randy Brukardt
2008-07-11  0:03       ` Adam Beneschan
2008-07-11  0:50         ` Robert A Duff
2008-07-10 14:37 ` Robert A Duff
2008-07-10 15:19   ` Adam Beneschan
2008-07-10 18:36     ` Dmitry A. Kazakov [this message]
2008-07-11  0:43       ` Robert A Duff
2008-07-11  7:39         ` Dmitry A. Kazakov
2008-07-11  9:06           ` christoph.grein
2008-07-11 14:24             ` Dmitry A. Kazakov
2008-07-11  0:29     ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox