comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Ada2012 Invariants and obaque types
Date: Tue, 21 Jun 2011 07:31:10 -0400
Date: 2011-06-21T07:31:10-04:00	[thread overview]
Message-ID: <wccmxhbv2td.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 239a78ad-0937-4a7a-8163-231430fd5ffe@k27g2000yqn.googlegroups.com

Martin <martin.dowie@btopenworld.com> writes:

> A fairly common Ada idiom is to define the full view of a private type
> using an incomplete declaration. Thus leaving the actual
> implementation to the package spec.

Body?

>...Trying this out with the public
> view defined with an invariant lead to a compiler error - is this:
>
> a) expected?
> b) an unexpected consequence? or
> c) a compiler bug?
>
> Example:
> package P1 is
>    type T1 is tagged private
>       with Invariant => Is_Valid (T1);
>    function Create               return T1;
>    function Is_Valid (This : T1) return Boolean;
> private
>    type Imp;
>    type T1 is
>       record
>          I : Imp;
>       end record;
> end P1;

This has nothing to do with invariants.  Incomplete types can only
be used in very restricted ways.  Not as components.  You need to
use an access type.

This dates back to Ada 83 -- it's always been illegal, and still is.

When compiling clients of P1 that declare objects of type T1,
how would the compiler know the size?  It could treat it as
dynamic, or it could take a peek at the body, but if either of
those was the intended compilation model, then there would be no
need for private parts in the first place -- we'd put the completion
of a private type in the body, where it belongs.

I suggest you erase the invariant, fix the errors, and then put the
invariant back in.  There's nothing wrong with your invariant.

- Bob



  parent reply	other threads:[~2011-06-21 11:31 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-21  8:53 Ada2012 Invariants and obaque types Martin
2011-06-21 10:27 ` Yannick Duchêne (Hibou57)
2011-06-21 10:36   ` Martin
2011-06-21 10:46   ` Martin
2011-06-21 18:42     ` Yannick Duchêne (Hibou57)
2011-06-21 10:43 ` Ludovic Brenta
2011-06-21 10:53   ` Martin
2011-06-21 11:14 ` Martin
2011-06-21 11:31 ` Robert A Duff [this message]
2011-06-21 11:48   ` Martin
2011-06-21 12:01   ` Martin
2011-06-21 12:13     ` Robert A Duff
2011-06-21 12:22       ` Martin
2011-06-21 12:54         ` Robert A Duff
2011-06-21 13:00           ` Martin
2011-06-21 12:08 ` Dmitry A. Kazakov
2011-06-21 12:17   ` Georg Bauhaus
2011-06-21 12:31     ` Dmitry A. Kazakov
2011-06-21 13:29       ` Georg Bauhaus
2011-06-21 14:42         ` Dmitry A. Kazakov
2011-06-21 18:37   ` Yannick Duchêne (Hibou57)
2011-06-21 18:53     ` Dmitry A. Kazakov
2011-06-21 19:34       ` Vinzent Hoefler
2011-06-21 20:52         ` Dmitry A. Kazakov
2011-06-21 21:50           ` Vinzent Hoefler
2011-06-22  7:55             ` Dmitry A. Kazakov
2011-06-21 21:18       ` Manuel Collado
2011-06-22  8:00         ` Dmitry A. Kazakov
2011-06-22 10:39 ` Egil Høvik
2011-06-22 13:57   ` Martin
2011-06-23 16:21 ` anon
replies disabled

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