comp.lang.ada
 help / color / mirror / Atom feed
* Generic instantiation with constrained subtype
@ 2008-08-23 12:59 Simon Wright
  2008-08-23 19:09 ` Jeffrey R. Carter
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Wright @ 2008-08-23 12:59 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-08-23 20:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-23 12:59 Generic instantiation with constrained subtype Simon Wright
2008-08-23 19:09 ` Jeffrey R. Carter
2008-08-23 20:24   ` Simon Wright

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