W. Wesley Groleau x4923 wrote:
>
> I beg your indulgence for a technical question in this advocacy forum.
> Our NNTP feed has been broken for months, and I can't seem to get to
> comp.lang.ada through any of the other gateways I know of.
>
> In the sample code at the end of this message, one compiler rejects all
> four instantiations, citing RM95 12.5.4(3).  Another compiler accepts
> them.

The instantiations should be rejected.  A designated subtype
is determined when an access type is declared, and is the
same for all subtypes of the access type, even if the
access subtypes impose constraints on the designated subtype.
Hence, none of these match statically, because the designated
subtype of the actual is unconstrained in each case, whereas
the designated subtype of the formal is constrained in each case.

RM paragraph 3.10(10) defines designated subtype, and it is
determined completely by the subtype_indication given in the
access type definition.  Constraints imposed on the access type
do not change this definition.

> The Reference Manual is extremely obscure on this.  I had to do a lot of
> looking to conclude that they DO statically match---and of course, I could
> be wrong.  :-)  Some of the places I looked are  3.7, 3.10, and 4.9.1
> Although notes and examples are "informative" (which I assume means "not
> binding" as in LRM 83), it was indeed "informative" to see that 3.8.1 (24,
> 25, 27) and 3.10 (22, 24) present the same construct.
>
> Opinions?  Since this is the wrong forum for this, please email me
> directly instead of to the list.

This doesn't really seem like the wrong forum, though I suppose
comp.lang.ada would be better.

> package Base is
>
>    type Enum is (Int, Char, FP, Str_80);
>
>    Default_Name : constant String := "Undefined";
>
>    type Variant (Discriminant : Enum := Char) is
>       record
>         Name : String (1 .. Default_Name'Length) := Default_Name;
>         case Discriminant is
>            when Int =>     FI : Integer;
>            when Char =>    FC : Character;
>            when FP =>      FF : Float;
>            when Str_80 =>  FS : String ( 1 .. 80 );
>         end case;
>
>       end record;
>
>    type Acc_Var is access Variant;
>
> end Base;
>
> generic
>
>    type Variable is private;
>    type Pointer  is access Variable;
>
> package Take_Up_Space is
>
>    pragma Elaborate_Body (Take_Up_Space);
>
> end Take_Up_Space;
>
> package body Take_Up_Space is
>
>    Memory_Hog : Pointer;
>
> begin
>
>    for I in 1 .. 100 loop
>
>       Memory_Hog := new Variable;
>
>    end loop;
>
> end Take_Up_Space;
>
> with Base;
>  use Base;   -- for enum literals
>
> with Take_Up_Space;
>
> with Ada.Text_IO;
>  use Ada.Text_IO;
>
> procedure Test_Matching is
>    subtype Int_Var is Base.Variant (Int);
>
>    subtype FP_Var is Base.Variant (FP);
>
>    subtype Char_Var is Base.Variant (Char);
>
>    subtype Str_80_Var is Base.Variant (Str_80);
>
>    subtype Int_Ptr is Base.Acc_Var (Int);
>
>    subtype FP_Ptr is Base.Acc_Var (FP);
>
>    subtype Char_Ptr is Base.Acc_Var (Char);
>
>    subtype Str_80_Ptr is Base.Acc_Var (Str_80);
>
>    package Int_Waster is new Take_Up_Space ( Variable => Int_Var,
>                                              Pointer  => Int_Ptr );
>
>    package FP_Waster is new Take_Up_Space ( Variable => FP_Var,
>                                             Pointer  => FP_Ptr );
>
>    package Char_Waster is new Take_Up_Space ( Variable => Char_Var,
>                                               Pointer  => Char_Ptr );
>
>    package Str_80_Waster is new Take_Up_Space ( Variable => Str_80_Var,
>                                                 Pointer  => Str_80_Ptr );
>
> begin
>
>    null;
>
> exception
>
>    when Storage_Error =>
>
>       Put_Line ("Not enough memory.");
>
> end Test_Matching;

--
-Tucker Taft   [log in to unmask]   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA