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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,a568c3c1e0be03bf X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.204.157.134 with SMTP id b6mr390474bkx.5.1339692031009; Thu, 14 Jun 2012 09:40:31 -0700 (PDT) Path: e27ni47916bkw.0!nntp.google.com!news1.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Streams and abnormality Date: Tue, 12 Jun 2012 08:01:03 -0700 (PDT) Organization: http://groups.google.com Message-ID: <9cd8589d-e8c1-402e-822e-d57aac39948e@googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1339517102 30020 127.0.0.1 (12 Jun 2012 16:05:02 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 12 Jun 2012 16:05:02 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-06-12T08:01:03-07:00 List-Id: On Tuesday, June 12, 2012 2:31:17 AM UTC-7, Simon Wright wrote: > Using this code with GCC 4.6, 4.7 and GNAT GPL 2011, >=20 > Str : aliased {a child of Root_Stream_Type}; > subtype Short_Int is Integer range 0 .. 42; > S : Short_Int; > begin > Integer'Output (Str'Access, -1); > S :=3D Short_Int'Input (Str'Access); > Put_Line (S'Img & " " & S'Valid'Img); >=20 > I get the output " 63 FALSE". >=20 > My reading of AARM05 13.9.1(4..6) [1] is that - because S is a scalar > object - S should not have been allowed to become abnormal; I think > that, instead, some exception (Constraint_Error? Data_Error?) should > have been raised. >=20 > [1] http://www.adaic.org/resources/add_content/standards/05aarm/html/AA-1= 3-9-1.html You're right; it should have raised Constraint_Error, but I think it has no= thing to do with 13.9.1, because Short_Int'Input is defined to return a val= ue of type Short_Int'Base, not Short_Int (13.13.2(23), which actually says = Short_Int'Input returns the *type* T of which Short_Int is a subtype, but I= think that's the same thing). Thus, in a normal situation, the result of = Short_Int'Input *cannot* be an invalid value, because (if Integer'Size =3D = 16) then 16 bits will be read from the stream, and all possible 16-bit bit = patterns are valid values of Short_Int'Base. I don't see anything in 13.13= .2 that says the function result of ST'Input is checked against the constra= ints defined for subtype ST. The Constraint_Error should occur during the = assignment, when the value of the expression (of type S'Base) needs to be c= onstraint-checked before assigning into S, just as it would if *any* functi= on returning Integer appeared on the right side of the assignment.=20 After rereading 13.9.1, though, I think it's wrong to suppose that there's = a dichotomy between "abnormal" and "must raise an exception". 13.9.1 appea= rs to define two different concepts, abnormal objects and objects with inva= lid representation. A scalar object can have invalid representation withou= t being abnormal, and this condition could be produced by stream operations= , such as T'Input where T is an enumeration type. It looks like the main d= ifference between "abnormal objects" and "scalars with invalid representati= on" is that the latter is a "bounded error" and there is more definition ab= out what programs are required to do with scalars to ensure they don't make= a huge mess. But raising an exception isn't required. -- Adam