Evaluation of an attribute prefix having an un 86-12-01 AI-00155/08 1 | !standard 03.02.01 (18) 86-12-01 AI-00155/08 | !standard 07.04.03 (04) | !class binding interpretation 84-01-10 | !status approved by WG9/AJPO 86-11-26 | !status approved by Director, AJPO 86-11-26 | !status approved by WG9/Ada Board 86-11-18 !status committee-approved 86-06-02 (reviewed) !status committee-approved 85-12-11 (subject to further editorial review) !status committee-approved (10-0-0) 85-09-05 (subject to editorial review) !status work-item 85-02-03 !status received 84-01-10 !references 83-00230, 83-00653 !topic Evaluation of an attribute prefix having an undefined value !summary 86-05-05 The execution of a program is erroneous if the name of a deferred constant is evaluated before the full declaration of the constant has been elaborated. Evaluation of the name of a scalar variable is not erroneous, even if the variable has an undefined value, if the name occurs as the prefix for the attribute ADDRESS, FIRST_BIT, LAST_BIT, POSITION, or SIZE. (In these cases, the value of the variable is not needed.) !question 85-10-31 7.4.3(4) says "The execution of a program is erroneous if it attempts to use the value of a deferred constant before the elaboration of the corresponding full declaration." Is the declaration of V in the example below erroneous? package P is type T is private; DC : constant T; -- deferred constant type REC is record C : INTEGER := DC'SIZE; -- legal (7.4.3(2)) end record; V : REC; -- erroneous? private ... end P; Note that the value of DC is not needed to determine DC'SIZE, and moreover, 4.1(9) says the evaluation of the prefix DC only determines the entity denoted by the name (not its value). Now consider: X : INTEGER; Y : INTEGER := X'SIZE; X has an undefined value. Is the evaluation of X'SIZE erroneous? Note that Evaluation of an attribute prefix having an un 86-12-01 AI-00155/08 2 3.2.1(18) says: "The execution of a program is erroneous if it attempts to evaluate a scalar variable with an undefined value," and 4.1.4(5) requires "evaluation" of X. !recommendation 86-05-05 If the prefix of an attribute denotes a constant declared by a deferred constant declaration and evaluation of the prefix is attempted before the deferred constant's full declaration has been elaborated, execution of the program is erroneous. Evaluation of the name of a scalar variable is not erroneous, even if the variable has an undefined value, if the name occurs as the prefix of an attribute and the value of the variable is not required to determine the attribute's value. !discussion 86-05-05 First, the declaration of REC is legal according to the wording of 7.4.3(2), which allows the use of a name that denotes a deferred constant "in the default expression for a record component". "In the default expression" includes use as a prefix and as the argument of a function (e.g., the default expression could be F(DC) if F were suitably declared; of course, an attempt to invoke F before elaboration of its body would raise PROGRAM_ERROR). (Note: DC'SIZE cannot be replaced with T'SIZE in the question because 7.4.1(4) forbids the use of an incompletely declared type name "within" a simple expression.) Second, 13.7.2(5) requires that the prefix of the SIZE attribute denote an object (or a subtype). Elaboration of the declaration of V includes evaluation of the default expression DC'SIZE, but DC at that point does not yet denote an object; only the full declaration of the constant creates an object [3.2.1(7)]. The evaluation of such a prefix should therefore be considered an error. Since this error cannot in general be detected prior to execution, and since it is not reasonable to require that an exception be raised when such a prefix is evaluated, it is best to consider it the programmer's responsibility to avoid having such prefixes evaluated, i.e., evaluation of such prefixes should be considered to make execution of the program erroneous. Execution of a program is not to be considered erroneous if the prefix of a predefined attribute is a scalar variable and the prefix has an undefined value when it is evaluated. (Such a prefix is only legal if it is the prefix of the attribute ADDRESS, FIRST_BIT, LAST_BIT, POSITION, or SIZE; such an evaluation only determines the entity denoted by the name [4.1(9, 10)] and does not require any value for the variable.) Evaluation of the initialization expression for Y (i.e., evaluation of X'SIZE) was not intended to be considered erroneous even though the prefix has an undefined value.