CVS difference for ai05s/ai05-0038-1.txt
--- ai05s/ai05-0038-1.txt 2007/01/23 05:35:41 1.1
+++ ai05s/ai05-0038-1.txt 2007/04/11 00:57:10 1.2
@@ -1,7 +1,8 @@
-!standard A.10.5(37) 07-01-22 AI05-0038-1/01
+!standard A.10.5(37) 07-04-06 AI05-0038-1/02
!standard A.10.7(8/1)
!standard A.10.7(10)
!standard A.10.7(12)
+!standard A.10.8(10)
!class binding interpretation 07-01-12
!status work item 07-01-12
!status received 06-11-27
@@ -16,6 +17,8 @@
(2) procedures Look_Ahead and Get_Immediate raise Status_Error if the file is not open.
+(3) procedure Get for a modular type raises Data_Error if the value is not in the subtype Num.
+
!question
(1)
@@ -29,6 +32,12 @@
statement that an empty file raises Status_Error. Surely that should happen
for these routines.
+(3)
+A.10.8(10) indicates that Get raises Data_Error only if the value is outside
+of the base range. So what happens if the value is outside of the subtype Num
+but inside the base range? The Note A.10.8(24) says that it raises Data_Error,
+but there is no justification for this statement.
+
!recommendation
(See Summary.)
@@ -48,6 +57,11 @@
to A.10.7(8/1), A.10.7(10), A.10.7(12) before the sentence starting "Mode_Error is
raised..."
+(3) Change A.10.8(10) to:
+
+The exception Data_Error is propagated if the sequence of characters read does not
+form a legal integer literal or if the value obtained is not of the subtype Num.
+
!discussion
(1) This error even appears in Ada 83. Clearly, Set_Line(1) should just call New_Page if
@@ -61,12 +75,22 @@
was intended to specify the rule in the definition of these routines, rather than
changing the blanket definition.
+(3) Get could raise Constraint_Error in this case, but there doesn't seem to be any
+value in it being different than Get for Integers. Moreover, such a value cannot be
+Put (as it would raise Constraint_Error), so there is little reason to be able to
+read it.
+
+[Editor's note: I did a bit of research on this to figure out when/why it was changed.
+Interestingly, RM9X 3.0 has the wording that we're going to switch to verbatium. It was
+changed in RM9x 4.0 to the current wording without explanation. Thus the rule is clearly
+intentional, but what the author was thinking is lost to the mists of time.]
+
--!corrigendum A.18.2(239/2)
!ACATS test
-Both of these changes just confirm the expected behavior (which doesn't match the
+All of these changes just confirm the expected behavior (which doesn't match the
wording), so there isn't a significant need for testing them.
!appendix
@@ -116,3 +140,57 @@
****************************************************************
+!topic Inconsistent handling of Get for modular types
+!reference RM A.10.8(10)
+!from Christoph Grein 07-03-02
+!discussion
+Consider the following program fragment:
+
+ type Test_Modular is mod 2**10;
+ subtype Test_Range is Test_Modular range 0 .. +1000;
+ -- Test_Range'Base 0 .. 1023
+
+ package Test_Modular_Text_IO is new Ada.Text_IO.Modular_IO (Test_Range);
+ use Test_Modular_Text_IO;
+
+ Unsigned: Test_Modular;
+
+ Get (File, Unsigned);
+
+According to A.10.8(10), the value 1023 can be read into Unsigned
+without raising Data_Error (contrary to a signed integer). This is what
+Bob Duff told me when I asked about this behaviour:
+
+The RM seems inconsistent on this point. A.10.8(10) does indeed seem to say
+that the base range is what matters. However, this makes no sense, for several
+reasons:
+
+ - The subtype of the parameter is Num, not Num'Base, so it is impossible to
+ return 1023 in your example (unless we go completely outside normal Ada
+ semantics -- and Text_IO is supposed to be implementable in normal Ada
+ code).
+
+ - The NOTE in para 24 contradicts A.10.8(10):
+
+ For Modular_IO, execution of Get propagates Data_Error if the
+ sequence of characters read forms an integer literal outside the
+ range 0..Num'Last.
+
+ - To me, it makes no sense to raise Constraint_Error for 1023 but
+ Data_Error for 1025.
+
+ - Modular_IO.Put cannot put the number 1023, so why should Get be able to
+ read it?
+
+ - I see no value to the programmer in using the base range. If you want
+ the base range, instantiate with that subtype. (In fact, I'd say a good
+ rule of thumb is to never use subranges of modular types, nor arrays
+ indexed by modular types, except in special circumstances, such as
+ interfacing with C code.)
+
+Therefore, we're going to guess that A.10.8(10) is simply a mistake, and the
+intent is that Data_Error be raised for numbers outside the range of Num.
+
+End of quote.
+
+****************************************************************
Questions? Ask the ACAA Technical Agent