Version 1.1.1.1 of ais/ai-00138.txt
!standard 04.02 (10) 97-11-14 AI95-00138/01
!class confirmation 96-05-07
!status ARG Approved 10-0-2 97-11-14
!status work item 96-05-08
!status received 96-05-07
!priority Low
!difficulty Easy
!subject Null String Literals when the Index Type is Modular
!summary 96-05-08
If the index subtype of a string type is a modular subtype whose lower
bound is zero, then the evaluation of a null string_literal raises
Constraint_Error.
!question 96-05-08
Consider the following code fragment:
type T is mod 2**32;
type A is array (T range <>) of Character;
X : A := "";
What are the bounds of X?
RM95 4.3.3(26) unambiguously defines the lower bound of X: "For a
positional_array_aggregate ... the lower bound is ... that of the
corresponding index subtype." So X'First is 0.
Then, RM95 4.2(10) says that "for a null string literal, the upper bound is
the predecessor of the lower bound."
There doesn't seem to be a definition of the word "predecessor" in the RM (it
doesn't appear in the index). The closest thing to predecessor appears to be
the attribute Pred. But that doesn't make sense, since T'Pred (0) would be
T'Last, meaning that the null string literal would have non-zero length!
What is the intent here? In particular, what is the meaning of "predecessor"
in 4.2(10)?
!response 96-05-08
The meaning of "predecessor" is indeed the same as the attribute Pred.
However, 4.2(11) says:
For the evaluation of a null string literal, a check is made that its
lower bound is greater than the lower bound of the base range of the
index type.
In the above example, the lower bound of the null string_literal is 0,
which is not greater than the lower bound of T'Base, which is also 0.
Thus, Constraint_Error is raised, so the fact that the upper bound of
the string_literal "would have been" 2**32 is irrelevant.
!appendix
!section 4.2(10)
!subject Bounds of a null string literal when the index type is modular
!reference RM95 4.2(10)
!reference RM95 4.3.3(26)
!from Pascal Leroy 96-04-29
!reference 96-5528.a Pascal Leroy 96-4-29>>
!discussion
Consider the following code fragment:
type T is mod ...;
type A is array (T range <>) of Character;
X : A := "";
What are the bounds of X?
RM95 4.3.3(26) unambiguously defines the lower bound of X: "For a
positional_array_aggregate ... the lower bound is ... that of the
corresponding index subtype." So X'First is 0.
Then, RM95 4.2(10) says that "for a null string literal, the upper bound is
the predecessor of the lower bound."
There doesn't seem to be a definition of the word "predecessor" in the RM (it
doesn't appear in the index). The closest thing to predecessor appears to be
the attribute Pred. But that doesn't make sense, since T'Pred (0) would be
T'Last, meaning that the null string literal would have non-zero length!
What is the intent here? In particular, what is the meaning of "predecessor"
in 4.2(10)?
****************************************************************
!section 4.2(10)
!subject Bounds of a null string literal when the index type is modular
!reference RM95 4.2(10)
!reference RM95 4.3.3(26)
!reference 96-5528.a Pascal Leroy 96-4-29
!reference AI95-00138
!reference RM95 4.9(34)
!from Keith Thompson 96-05-10
!reference 96-5544.a Keith Thompson 96-5-10>>
!discussion
The summary of AI95-00138 says
> If the index subtype of a string type is a modular subtype whose lower
> bound is zero, then the evaluation of a null string_literal raises
> Constraint_Error.
This is true only if the modular subtype is non-static. If the modular
subtype is static (as it is in the example), a null string literal
is illegal by RM95 4.9(34), which refers to a static expression that
is evaluated:
"The expression is illegal if its evaluation fails a language-defined
check other than Overflow_Check."
****************************************************************
Questions? Ask the ACAA Technical Agent