Generic instantiation with constrained subtype



I've been trying to write some test cases for the Booch Components and
came up with this.

The test case is written as a generic, to be instantiated with the
appropriate Container type. This is fine for the definite containers
(ie, ones like No_Problem below) but fails for the Bounded forms, which
use the Unconstrained/Constrained technique.

This is the example:

-----------------------------------------------------------------------
package Instantiation_Problem is

type Base is tagged null record;

type No_Problem is new Base with null record;

type Unconstrained (Constraint : Positive)
is new Base with null record;

subtype Constrained is Unconstrained (Constraint => 10);

generic
type T is new Base with private;
package G is end G;

package NP is new G (No_Problem);

package F is new G (Constrained);
-- ^--------------------18:24

package U is new G (Unconstrained);
-- ^--------------------21:24

end Instantiation_Problem;
-----------------------------------------------------------------------

and GNAT (GCC 4.3.0) says

instantiation_problem.ads:18:24: constraint on actual is incompatible with formal
instantiation_problem.ads:18:24: instantiation abandoned
instantiation_problem.ads:21:24: actual subtype must be constrained
instantiation_problem.ads:21:24: instantiation abandoned

Am I going to have to rethink this? Have I used the wrong way of
specifying the generic parameter? Is GNAT confused? (note, at 21:24 it's
asking for a subtype, so why complain at 18:24?).

Ideally I'd like it if any solution could work with Ada 95 - these are
the Booch Ada 95 Components!

--S
.



Relevant Pages

  • Re: Questa AVM
    ... And if constraint randow was realy the thing everybody needed, ... Would be no technical problem to use a standardised package, ... language which unfortunately is not the case for VHDL. ... IEEE to standardize it and for EDA companies to support it. ...
    (comp.lang.vhdl)
  • Re: Operation can be dispatching in only one type
    ... The idea of deriving both types in one package looks like an attempt to ... general multiple dispatch wasn't ever going to be part ... Marker type that represents a particular point in the ... Actually I considered both cases with the requirement of the constraint ...
    (comp.lang.ada)
  • Re: Generic package parameters not externally visible : whats the rational ?
    ... surely increase the chance of name collisions outside of the package. ... type Int is range; ... That depends on the mental model of the discriminant. ... I am also in favor the "constraint" model, and yes, in this ...
    (comp.lang.ada)
  • Re: Constraints in tcltest1.0
    ... I am using jacl 1.4.1, which has tcltest1.0 package. ... $sum add 10 ... that constraint test seems wrong -- it should be checking the machine or os fields. ...
    (comp.lang.tcl)