From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,60fe876e7675f11 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.238.198 with SMTP id vm6mr14790638pbc.3.1328639552122; Tue, 07 Feb 2012 10:32:32 -0800 (PST) Path: lh20ni271367pbb.0!nntp.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news-out.readnews.com!transit3.readnews.com!xlned.com!feeder1.xlned.com!newsreader4.netcologne.de!news.netcologne.de!newsfeed.straub-nv.de!uucp.gnuu.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 07 Feb 2012 19:32:28 +0100 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Weird behavior with modular type References: <323fa219-509f-4605-95d9-42573655cf9d@i18g2000yqf.googlegroups.com> In-Reply-To: <323fa219-509f-4605-95d9-42573655cf9d@i18g2000yqf.googlegroups.com> Message-ID: <4f316e3c$0$6558$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 07 Feb 2012 19:32:28 CET NNTP-Posting-Host: 00826065.newsspool4.arcor-online.net X-Trace: DXC=N3L^Tc3YS[<]E=H1Q9`7874IUK:Lh>_cHTX3j=1K1kdj3cGk8 X-Complaints-To: usenet-abuse@arcor.de Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Date: 2012-02-07T19:32:28+01:00 List-Id: On 07.02.12 19:02, Adam Beneschan wrote: > On Feb 7, 9:24 am, Yannick Duch�ne (Hibou57) > 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;