From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Weird behavior with modular type
Date: Tue, 07 Feb 2012 19:32:28 +0100
Date: 2012-02-07T19:32:28+01:00 [thread overview]
Message-ID: <4f316e3c$0$6558$9b4e6d93@newsspool4.arcor-online.net> (raw)
In-Reply-To: <323fa219-509f-4605-95d9-42573655cf9d@i18g2000yqf.googlegroups.com>
On 07.02.12 19:02, Adam Beneschan wrote:
> 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.
This spit for the assignment to B seems to confirm:
| Node #44 N_Identifier "false" (Node_Id=1727) (analyzed)
| Rewritten: original node = N_Op_Lt "Olt" (Node_Id=42471)
| ...
| Chars = "false" (Name_Id=300001085)
| Is_Static_Expression = True
| Etype = N_Defining_Identifier "boolean" (Entity_Id=12s)
| Entity = N_Defining_Identifier "false" (Entity_Id=107s)
-gnatdg gives
b := false;
next prev parent reply other threads:[~2012-02-07 18:32 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
2012-02-07 18:32 ` Georg Bauhaus [this message]
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