From: Adam Beneschan <adam@irvine.com>
Subject: Re: Weird behavior with modular type
Date: Tue, 7 Feb 2012 10:02:40 -0800 (PST)
Date: 2012-02-07T10:02:40-08:00 [thread overview]
Message-ID: <323fa219-509f-4605-95d9-42573655cf9d@i18g2000yqf.googlegroups.com> (raw)
In-Reply-To: op.v9bjzvhzule2fv@douda-yannick
On Feb 7, 9:24 am, Yannick Duchêne (Hibou57)
<yannick_duch...@yahoo.fr> wrote:
>
> Now, the following, with added "Natural'Pos (...)", did not even compile:
>
> with Ada.Text_IO;
> procedure Bug is
>
> type Modular_Type is mod 256;
> subtype Index_Type is Natural range 1 .. 3;
>
> E : Modular_Type := 255;
> I : Index_Type := 3;
> B : Boolean;
>
> begin
> B := E < Natural'Pos (10 ** I);
> Ada.Text_IO.Put_Line (Boolean'Image (B));
> end Bug;
>
> That's counter intuitive. I would expect the first to behave as the
> second, with either a failure to compile or range error at run-time.
By the way, I don't see any reason this shouldn't compile, although
offhand I think it should raise a Constraint_Error at runtime (since
1024 would be the right argument of a function "<" (Left, Right : E)
return Boolean and 1024 can't be converted to E without a
Constraint_Error). When I compile on GNAT (4.5.2), it says "static
expression fails Constraint_Check". This looks like a GNAT bug,
though, because there's no static expression. Apparently it thinks
it's static because it knows the value of I must still be 3 at that
point, but that doesn't make it a static expression according to the
language rules, so the program shouldn't be rejected. (Inserting a
call to a null nested procedure before the first line of Bug makes the
error message go away.)
-- Adam
next prev parent reply other threads:[~2012-02-07 18:04 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-07 17:24 Weird behavior with modular type Yannick Duchêne (Hibou57)
2012-02-07 17:49 ` Jeffrey Carter
2012-02-07 18:06 ` Adam Beneschan
2012-02-07 18:21 ` Yannick Duchêne (Hibou57)
2012-02-08 6:53 ` J-P. Rosen
2012-02-08 15:29 ` Adam Beneschan
2012-02-09 3:37 ` Randy Brukardt
2012-02-07 18:15 ` Yannick Duchêne (Hibou57)
2012-02-07 17:53 ` Adam Beneschan
2012-02-07 17:54 ` Gautier write-only
2012-02-07 18:23 ` Yannick Duchêne (Hibou57)
2012-02-09 3:40 ` Randy Brukardt
2012-02-07 18:02 ` Adam Beneschan [this message]
2012-02-07 18:32 ` Georg Bauhaus
2012-02-07 18:13 ` Yannick Duchêne (Hibou57)
2012-02-07 18:15 ` Adam Beneschan
2012-02-07 18:35 ` Yannick Duchêne (Hibou57)
2012-02-07 18:40 ` Adam Beneschan
2012-02-07 19:22 ` Yannick Duchêne (Hibou57)
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox