!standard A.4.3(56.2/2) 07-05-23 AI05-0056-1/01
!standard A.4.3(58/2)
!standard A.4.3(58.1/2)
!standard A.4.3(58.2/2)
!standard A.4.3(58.3/2)
!standard A.4.3(58.5/2)
!standard A.4.3(60/2)
!standard A.4.3(60.1/2)
!standard A.4.3(60.2/2)
!standard A.4.3(60.3/2)
!class binding interpretation 07-05-23
!status work item 07-05-23
!status received 07-05-10
!priority Low
!difficulty Easy
!qualifier Error
!subject Wrong result for Index functions
!summary
Index returns 0 when searching a null string; it does not
raise Index_Error.
!question
Even though we're careful to not call it an equivalence, the equivalence given in
A.4.3(58-58.3/2) causes an incompatibility with Ada 95. Consider:
S : String (1..0);
I : Natural := Index (S, "foo");
In Ada 95 the function Index would return 0, indicating that the pattern
was not found. Fine.
In Ada 2005 the above call is defined to be Index (S, "foo", From => 1).
Unfortunately From is not in S'Range and this call raises Index_Error.
Was this incompatibility intended? (No.)
!recommendation
(See Summary.)
!wording
Replace A.4.3(56.2/2) by:
If From is not in Source'Range, then Index_Error is propagated.
Otherwise if Going = Forward, returns
Index (Source(From .. Source'Last), Pattern, Forward, Mapping);
otherwise returns
Index (Source(Source'First .. From), Pattern, Backward, Mapping);
Replace A.4.3(58-58.3/2) by (this is the original Ada 95 wording):
Each Index function searches for a slice of Source, with length
Pattern'Length, that matches Pattern with respect to Mapping; the
parameter Going indicates the direction of the lookup. If
Going = Forward, then Index returns the smallest index I such that
the slice of Source starting at I matches Pattern.
If Going = Backward, then Index returns the largest index I such
that the slice of Source starting at I matches Pattern. If there
is no such slice, then 0 is returned. If Pattern is the null string
then Pattern_Error is propagated.
Replace A.4.3(58.5/2) by:
If From is not in Source'Range, then Index_Error is propagated.
Otherwise if Going = Forward, returns
Index (Source(From .. Source'Last), Set, Test, Forward);
otherwise returns
Index (Source(Source'First .. From), Set, Test, Backward);
Replace A.4.3(60-60.3/2) by (this is the original Ada 95 wording):
Index searches for the first or last occurrence of any of a set
of characters (when Test=Inside), or any of the complement of a
set of characters (when Test=Outside). It returns the smallest
index I (if Going=Forward) or the largest index I (if
Going=Backward) such that Source(I) satisfies the Test condition
with respect to Set; it returns 0 if there is no such Character
in Source.
!discussion
Note that the same problem occurs in the wording for the set version of
Index.
Patching up the Amendment wording would require adding a lengthy sentence to
A.4.3(58/2) and A.4.3(60/2) to cover the case of a null string (which should
return 0, unless the pattern is null). That is longer than the original wording,
and still has the possibility of incompatibilites. As such we restore the
Ada 95 wording for A.4.3(58/2) and A.4.3(60/2).
In order to avoid unnecessary diferences between these functions, we reword
the new A.4.3(56.2/2) and A.4.3(58.5/2). (The author of the original wording
considered this option originally, but didn't do it thinking it would be
shorter and simpler the other way, which did not turn out to be true.)
--!corrigendum A.4.3(26/2)
!ACATS Test
!appendix
****************************************************************