From: "Jeffrey R. Carter" <jrcarter@acm.org>
Subject: Re: Brain bug or GNAT bug?
Date: Thu, 01 Mar 2007 05:07:35 GMT
Date: 2007-03-01T05:07:35+00:00 [thread overview]
Message-ID: <rctFh.10672$u93.3787@attbi_s21> (raw)
In-Reply-To: <C20BD14B.9A6F1%yaldnif.w@blueyonder.co.uk>
(see below) wrote:
>
>>> generic
>>> type modular is mod <>;
>>> package try is
>>>
>>> type DT1 (the_size : modular) is limited private;
>>>
>>> -- subtype bounded is modular;
>>> subtype bounded is modular range 1..9;
> But if the declaration of bounded compiles,
> the range of bounded must be a subset of the range of modular,
> so DT2.the_size must be in the range of modular.
> The rule at ARM 3.7(15) seems overly restrictive.
Consider:
with Ada.Command_Line;
procedure Modular_Subtype is
type Modular is mod 2 ** 32;
Low : constant Modular :=
Modular'Value (Ada.Command_Line.Argument (1) );
High : constant Modular :=
Modular'Value (Ada.Command_Line.Argument (2) );
subtype Mod_Sub is Modular range Low .. High;
generic -- Modular_Parameter
type Modular is mod <>;
package Modular_Parameter is
subtype Bounded is Modular range 1 .. 9; -- Line 16
end Modular_Parameter;
package Instantiation is new Modular_Parameter (Modular => Mod_Sub);
begin -- Modular_Subtype
null;
end Modular_Subtype;
This compiles (with a warning that Instantiation is not referenced).
Since the instantiation cannot be checked during compilation, it is
checked at run time. Here's a sample run:
D:\Code>modular_subtype 10 24
raised CONSTRAINT_ERROR : modular_subtype.adb:16 range check failed
Here's another:
D:\Code>modular_subtype 0 10
D:\Code>
--
Jeff Carter
"I unclog my nose towards you."
Monty Python & the Holy Grail
11
next prev parent reply other threads:[~2007-03-01 5:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-28 23:44 Brain bug or GNAT bug? (see below)
2007-03-01 0:11 ` Ludovic Brenta
2007-03-01 0:39 ` (see below)
2007-03-01 5:07 ` Jeffrey R. Carter [this message]
2007-03-01 8:45 ` Ludovic Brenta
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox