A qualified expression is used to state explicitly the type, and possibly the subtype, of an operand that is the given expression or aggregate.
qualified_expression ::= type_mark'(expression) | type_mark'aggregate
The operand must have the same type as the base type of the type mark. The value of a qualified expression is the value of the operand. The evaluation of a qualified expression evaluates the operand and checks that its value belongs to the subtype denoted by the type mark. The exception CONSTRAINT_ERROR is raised if this check fails.
type MASK is (FIX, DEC, EXP, SIGNIF); type CODE is (FIX, CLA, DEC, TNZ, SUB); PRINT (MASK'(DEC)); -- DEC is of type MASK PRINT (CODE'(DEC)); -- DEC is of type CODE for J in CODE'(FIX) .. CODE'(DEC) loop ... -- qualification needed for either FIX or DEC for J in CODE range FIX .. DEC loop ... -- qualification unnecessary for J in CODE'(FIX) .. DEC loop ... -- qualification unnecessary for DEC DOZEN'(1 | 3 | 5 | 7 => 2, others => 0) -- see 4.6
Whenever the type of an enumeration literal or aggregate is not known from the context, a qualified expression can be used to state the type explicitly. For example, an overloaded enumeration literal must be qualified in the following cases: when given as a parameter in a subprogram call to an overloaded subprogram that cannot otherwise be identified on the basis of remaining parameter or result types, in a relational expression where both operands are overloaded enumeration literals, or in an array or loop parameter range where both bounds are overloaded enumeration literals. Explicit qualification is also used to specify which one of a set of overloaded parameterless functions is meant, or to constrain a value to a given subtype.
References: aggregate, array, base type, bound of a range, constraint_error exception, context of overload resolution, enumeration literal, expression, function, loop parameter, overloading, raising of exceptions, range, relation, subprogram, subprogram call, subtype, type, type mark.
Rationale references: 3.5 Aggregates, 3.6 Expressions
Address any questions or comments to firstname.lastname@example.org.