[net.lang.ada] Message of 13-Oct-85 15:46:20

Mailer@USC-ECLB.ARPA (The Mailer Daemon) (10/14/85)

Message failed for the following:
STAGER@EGLIN-VAX.ARPA.#Internet: 550 User "STAGER" Unknown.
harbaughs@EGLIN-VAX.ARPA.#Internet: 550 User "harbaughs" Unknown.
	    ------------
Return-Path: <siemens2@spice.cs.cmu.edu>
Received: from SPICE.CS.CMU.EDU (for SPICE.CS.CMU.EDU) by USC-ECLB.ARPA; Tue 1 Oct 85 09:52:11-PDT
Date: 1 Oct 1985 12:50:37-EDT
From: Siemens2@SPICE.CS.CMU.EDU
To: INFO-ADA@ECLB
ReSent-Date: Sun 13 Oct 85 15:46:20-PDT
ReSent-From: INFO-ADA@USC-ECLB.ARPA
ReSent-To: info-ada@USC-ECLB.ARPA
ReSent-Message-ID: <12150885277.35.INFO-ADA@USC-ECLB.ARPA>


I have come across what appears to be an inconsistency in Ada.  Perhaps
someone can explain why this is.

I want to use a generic package that will manage arbitrary objects for me.
It will create and destroy my objects for me and I do not care about the
implementation of this package.  This is easy enough to do in Ada with a
generic package.

Consider the following specification and ignore the fact that there is no
body here.

-----------------------------------------------------------------
generic

  type element is private;

package Object_Mgr is

  some_generic_object: element;

end Object_Mgr;
-----------------------------------------------------------------

The problem I have come across occurs when trying to instantiate such a
generic package where one of the actual parameters is an unconstrained type
with discriminants.  This is definitely illegal as stated in the LRM
(section 12.3.2 or 12.3.2[4] to be more specific).  I understand that I am
not allowed to perform this instantiation because if there is a declaration
of an object with this type in the generic, then I have defined an object
which is unconstrained.  This is clearly illegal in Ada.  But why can't I
instantiate the generic if the actual type has a default value for the
discriminant?  In this case all objects that I would declare in the generic
package with this type would automatically be constrained by the default
value given in the declaration of the actual type.

What I want to know is why I can normally declare an object whose type has a
discriminant with a default value, but when using generics, this property does
not carry over.

The following piece of code will serve to illustrate this problem.  You can
try and compile it if you'd like so that you can see what happens.

-----------------------------------------------------------------
with Object_Mgr;
procedure Test is

  type object (x: boolean := false) is   -- Notice the default value here
    record
      case x is
	when true  => field1: integer;
	when false => field2: character;
      end case;
    end record;

  some_object: object;  -- This is OK because the discriminant has a default
                        -- value in the type declaration


  package My_Object_Mgr is new Object_Mgr (element => object);
  
  -- The compiler does like this instantiation because there is a 
  -- declaration of an object with the formal type 'element' 
  -- in the generic package.  See section 12.3.2[4] of the LRM.
  -- Since the actual type, 'object', has a default value, I think 
  -- that this should not be a problem.  This appears to be inconsistent
  -- to me.

begin
  null;
end Test;
-----------------------------------------------------------------

Steve Rosen
Siemens Research and Technology Laboratories
Princeton, NJ

USENET: {ihnp4|princeton|adrvax}!siemens!gypsy!rosen
ARPA:   siemens!rosen@TOPAZ
-------