comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Construction initialization problem
Date: Thu, 4 Dec 2008 09:35:23 -0800 (PST)
Date: 2008-12-04T09:35:23-08:00	[thread overview]
Message-ID: <80b2a531-3c9e-48c0-a809-2d6b3e1c20da@r10g2000prf.googlegroups.com> (raw)
In-Reply-To: oscmgxrpod50$.g7h7snlssha0$.dlg@40tude.net

On Dec 4, 8:08 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> Consider this:
>
>    type A is tagged limited null record;
>    type B (X : not null access A'Class) is tagged limited null record;
>
> Now we want to specialize B so that its instances would already contain A:
>
>    type C is new B with record
>       Y : aliased A;
>    end record;
>
> Now there seems no way to either create an object of C so that C.X would
> point to C.Y or else to derive from C a new type without discriminant:
>
>    type D is new C (X => C.Y'Access) with null record; -- Illegal
>    type D is new C (X => D.Y'Access) with null record; -- Illegal
>

On a related note, you can't do this either:

   type Rec1 is tagged null record;

   type Rec2 (D : access Rec1) is tagged limited record ... end
record;

   type Rec3 is record
      F1 : aliased Rec1;
      F2 : Rec2 (Rec3.F1'access);
   end record;

The rule preventing this is in 3.8, which says that the only component
of "current instance" that you can use is a noninherited
discriminant---and F1 is not a discriminant.  But offhand, I don't
think this restriction is necessary when the component is used as the
prefix of 'Access.  There shouldn't be any accessibility level issues,
I think.  Some care might be needed to get the language rules right in
case the component is in a variant part, but other than that I can't
think of any difficulties either in adding a rule to allow this or in
implementation.  Of course that doesn't mean there aren't any
difficulties, just that I can't think of them.

Simply adding that rule wouldn't quite solve Dmitry's problem, since
in this case:

   type D is new C (X => D.Y'Access) with null record; -- Illegal

he's trying to use a current instance in a discriminant, which a
different clause in 3.8(12) makes illegal.  Also, the issue of writing
an allocator for type C whose discriminant refers to C would seem to
require new syntax---maybe if we borrow the "extended return" idea?

   New_Obj := new ZZZ : C (X => ZZZ.Y'Access);

                              -- Adam







  reply	other threads:[~2008-12-04 17:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-04 16:08 Construction initialization problem Dmitry A. Kazakov
2008-12-04 17:35 ` Adam Beneschan [this message]
2008-12-04 22:17 ` Randy Brukardt
2008-12-04 23:02   ` Adam Beneschan
2008-12-06  1:47     ` Randy Brukardt
2008-12-05  9:00   ` Dmitry A. Kazakov
2008-12-06  1:42     ` Randy Brukardt
2008-12-06 10:16       ` Dmitry A. Kazakov
replies disabled

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