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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,113cbde0422b98e8 X-Google-Attributes: gid103376,public From: smize@news.imagin.net (Samuel Mize) Subject: Why no constraint error? Date: 1997/03/20 Message-ID: <5gs20s$2g11@prime.imagin.net>#1/1 X-Deja-AN: 227172572 Organization: ImagiNet Communications Ltd, Arlington, Texas Reply-To: smize@imagin.net (Samuel Mize) Newsgroups: comp.lang.ada Date: 1997-03-20T00:00:00+00:00 List-Id: Greetings, all, The following question has come up on chat@gnat.com, but it's really a general Ada question and I'm throwing it out to comp.lang.ada. It's probably been asked and answered before, but I can't find a good explanation on DejaNews. The question is, why doesn't this code raise an exception when run under GNAT? pragma Normalize_Scalars; with Ada.Text_Io; procedure Test_Subrange_Checks is type T_Source is new Integer range 7 .. 10; type T_Target is new Integer range 7 .. 10; -- identical ranges Source: T_Source; -- initialized out of range by Normalize_Scalars Target: T_Target := 10; begin Target := T_Target (Source); -- no range check occurs!!!!!!!!!! Ada.Text_Io.Put_Line (T_Target'Image (Target)); end Test_Subrange_Checks; Per 13.9.1(9-11), evaluating the uninitialized variable quite properly returns an invalid value. However, in the assignment, this value "is converted to the subtype of the target" per 5.2(11). In type conversion, "[a]fter conversion of the value to the target type, if the target subtype is constrained, a check is performed that the value satisfies this constraint" per 4.6(51). 11.6(5) provides permission to skip language-defined checks if this would not "have some effect on the external interactions of the program." Since program output is an external file, this is an external effect per 1.1.3(8-9). If your reply is the following, please consider it already sent: * Trust me, GNAT is right. * Informally, it makes sense to omit this check, since the ranges of the types statically match. I'm looking for an ARM reference that makes it legal to omit the check named in 4.6(51) in this case. I want to understand the specific language rule, so I can tell when it will or won't apply. I'd appreciate email, but will also check this group for replies. Thanks very much for your time and attention. Samuel Mize -- Samuel Mize -- smize@imagin.net -- Team Ada (personal net account)