Implicit conversion of attributes that are functions AI00218/08 1
881108 BI WA
 !standard 04.06 (15) 881108 AI00218/08
!standard 03.06.01 (02)
!class binding interpretation 860415
!status approved by WG9 871207
!status panel/committeeapproved 870831 (reviewed)
!status panel/committeeapproved (900) 870217 (pending editorial review)
!status workitem 861118
!status returned to panel/committee by WG9/Ada Board 861118
!status panel/committeeapproved 860807 (reviewed)
!status committeeapproved (801) 860512 (pending editorial review)
!status workitem 860325
!status received 840313
!references 8300328, 8300374, 8300377
!topic Implicit conversion of attributes that are functions
!summary 870831
An expression of the form T'POS(X) can be converted implicitly to an integer
type.
If T'Attr is an implementationdefined attribute that is a function whose
result type is either universal_integer or universal_real, then an expression
of the form T'Attr(X1,...,Xn) can be converted implicitly to an integer type
or to a real type, respectively.
For a discrete range defined by a range and used in a constrained array
definition, in an iteration rule, or in the declaration of a family of
entries, an implicit conversion to the predefined type INTEGER is assumed if
each bound is either a numeric literal, a named number, an attribute, or a
function call having the form T'POS(X) or the form T'Attr(X1,...,Xn) (where
T'Attr is an implementationdefined attribute that is a function whose result
type is universal_integer) and the type of both bounds (prior to the implicit
conversion) is the type universal_integer.
!question 870831
Consider the following example:
type ENUM is (A, B);
V1 : INTEGER := ENUM'POS(A);
Is a sequence of lexical elements such as ENUM'POS(A) considered an attribute
(with prefix ENUM and attribute designator POS(A); see 4.1.4(2)) or a
function call (with name ENUM'POS and actual parameter part (A); see 6.4(2))?
Since ENUM'POS is defined to be a function (3.5.5(6)), it seems reasonable to
conclude that ENUM'POS(A) must be considered a function call (moreover, since
4.1.4(2) requires that the expression in an attribute designator be a static
universal expression, ENUM'POS(A) cannot be considered an attribute).
Function calls are not mentioned in 4.6(15) as implicitly convertible
operands. Is ENUM'POS(A) implicitly convertible even though it is considered
a function call?
Implicit conversion of attributes that are functions AI00218/08 2
881108 BI WA
A similar question arises for constrained array declarations and the rule
given in 3.6.1(2), e.g., is the following declaration legal, and is the index
subtype INTEGER range 1..1?
ARR : array (1..ENUM'POS(B)) of INTEGER;
Likewise, if an implementation defines an additional attribute T'Attr that is
a function whose result type is universal_integer (or universal_real), then
is T'Attr(X1,...,Xn) implicitly convertible to an integer (or real) type?
!recommendation 870831
An expression having the form T'POS(X) (for discrete type T and expression X
of type T) is implicitly converted to an integer type if and only if the
innermost enclosing complete context determines a unique (integer) target
type for the implicit conversion, and there is no legal interpretation of
this context without this conversion.
If T'Attr is an implementationdefined attribute that is a function whose
result type is either universal_integer or universal_real, then an expression
of the form T'Attr(X1,...,Xn), where X1, ..., Xn are appropriately typed
expressions, is implicitly converted to an integer type or a real type,
respectively, if and only if the innermost enclosing complete context
determines a unique (numeric) target type for the implicit conversion, and
there is no legal interpretation of this context without this conversion.
For a discrete range used in a constrained array definition and defined by a
range, an implicit conversion to the predefined type INTEGER is assumed if
each bound is either a numeric literal, a named number, an attribute, or a
function call having the form T'POS(X) (for discrete type T and expression X
of type T) or the form T'Attr(X1,...,Xn) (where T'Attr is an
implementationdefined attribute that is a function whose result type is
universal_integer, and X1, ..., Xn are appropriately typed expressions) and
the type of both bounds (prior to the implicit conversion) is the type
universal_integer. This rule also applies to a discrete range used in an
iteration rule (see 5.5) or in the declaration of a family of entries (see
9.5).
!discussion 870831
4.6(15) states:
An implicit conversion of an operand of type universal_integer to
another integer type, or of an operand of type universal_real to
another real type, can only be applied if the operand is either a
numeric literal, a named number, or an attribute;
The intention is that this wording apply to forms such as ENUM'POS(A) and T'
Attr(X1,...,Xn), even though such forms are, technically speaking, function
calls, not attributes. Thus, the declarations V1 and V2 in the question are
intended to be legal.
Implicit conversion of attributes that are functions AI00218/08 3
881108 BI WA
Similarly, 3.6.1(2) says:
For a discrete range used in a constrained array definition and
defined by a range, an implicit conversion to the predefined type
INTEGER is assumed if each bound is either a numeric literal, a
named number, or an attribute, and the type of both bounds (prior
to the implicit conversion) is the type universal_integer. ...
These rules apply also to a discrete range used in an iteration
rule (see 5.5) or in the declaration of a family of entries (see
9.5).
The intention is that this wording also apply to forms such as ENUM'POS(A)
and T'Attr(X1,...,Xn), even though such forms are not, technically speaking,
attributes.
Note that T'POS is the only languagedefined attribute that is a function
whose result type is a universal type. By 4.1.4(2) and A(25), the form T'
LENGTH(1) is an attribute, not a function call, since the attribute_
 designator includes the parenthesized universal_static_expression. Hence,
implicit conversion of T'LENGTH(1) is already allowed by 4.6(15) and
3.6.1(2).
 !appendix 881012

 *****************************************************************************

 !section 04.06 (15) Chuck Engle 881012 8301022
 !version 1983
 !topic AI00218/07 mentions nonexistent object

 There is a problem with AI00218/07 in that the discussion mentions in
 paragraph 2 the following, "Thus, the declarations V1 and V2 in the question
 ..." yet the question does not contain a V2. V2 is left over from a former
 version of this AI and thus the reference to it should just be removed from
 the discussion section.
