Implicit conversion of attributes that are functions AI-00218/08 1 88-11-08 BI WA | !standard 04.06 (15) 88-11-08 AI-00218/08 !standard 03.06.01 (02) !class binding interpretation 86-04-15 !status approved by WG9 87-12-07 !status panel/committee-approved 87-08-31 (reviewed) !status panel/committee-approved (9-0-0) 87-02-17 (pending editorial review) !status work-item 86-11-18 !status returned to panel/committee by WG9/Ada Board 86-11-18 !status panel/committee-approved 86-08-07 (reviewed) !status committee-approved (8-0-1) 86-05-12 (pending editorial review) !status work-item 86-03-25 !status received 84-03-13 !references 83-00328, 83-00374, 83-00377 !topic Implicit conversion of attributes that are functions !summary 87-08-31 An expression of the form T'POS(X) can be converted implicitly to an integer type. If T'Attr is an implementation-defined 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 implementation-defined 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 87-08-31 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 AI-00218/08 2 88-11-08 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 87-08-31 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 implementation-defined 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 implementation-defined 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 87-08-31 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 AI-00218/08 3 88-11-08 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 language-defined 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 88-10-12 | | ***************************************************************************** | | !section 04.06 (15) Chuck Engle 88-10-12 83-01022 | !version 1983 | !topic AI-00218/07 mentions non-existent object | | There is a problem with AI-00218/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. |