Consider all overloaded visible declarations simultaneously AI-00481/05 1
89-06-16 ra WA
| !standard 08.07 (12) 89-06-16 AI-00481/05
!standard 04.06 (03)
!class ramification 86-10-13
| !status WG9-approved 89-06-16
!status ARG-approved 88-10-03 (reviewed)
!status ARG-approved (13-0-0) 88-06-07 (pending editorial review)
!status work-item 87-03-18
!status received 86-10-13
!references 83-00831
| !topic Consider all overloaded visible declarations simultaneously
!summary 88-04-20
All visible declarations must be considered simultaneously when deciding
whether the operand of a type conversion has a unique resolution.
!question 87-03-18
8.7(7, 12) say:
When considering possible interpretations of a complete context,
the only rules considered are the syntax rules, the scope and
visibility rules, and the rules of the form described below.
(e) ... Similarly, the rules that require ... the type of the
operand of a type conversion, to be determinable independently of
the context (see ... 4.6, ...).
The referenced rule in 4.6(3) says:
The type of the operand of a type conversion must be determinable
independently of the context (in particular, independently of the
target type).
Consider the following example:
type TF1 is new INTEGER;
type TF2 is new INTEGER;
type TF3 is new INTEGER;
type TX1 is (X, Y); -- X1
type TX2 is (X, Z); -- X2
function F (A : TX1) return TF1; -- F1
function F (A : TX2) return TF2; -- F2
function F (A : TX2) return TF3; -- F3
Q : INTEGER := INTEGER( F(X) ); -- legal? (no)
Does the Standard permit the following argument to be used in the overload
resolution of F and X in the type conversion?
Consider all overloaded visible declarations simultaneously AI-00481/05 2
89-06-16 ra WA
If X is X2, there are two possible types for F(X), namely, TF2
and TF3. According to 4.6(3), this is illegal. According to
8.7(12), this part of 4.6 can be used in the overload resolution.
Hence, X2 is not a possible overload resolution for X.
If X is X1, the type of F(X) is determined, namely, as TF1, and
4.6(3) is satisfied.
Therefore, overload resolution is possible for F(X) and resolves
it to F1(X1).
Is this a correct interpretation of the Standard?
!response 87-08-13
8.7(2-3) say:
For overloaded entities, overload resolution determines the
actual meaning that an occurrence of an identifier has, whenever
the visibility rules have determined that more than one meaning
is acceptable at the place of this occurrence; overload
resolution likewise determines the actual meaning of an
occurrence of an operator or some basic operation.
At such a place all visible declarations are considered. The
occurrence is only legal if there is exactly one interpretation
of each constituent of the innermost complete context; ...
Since all visible declarations are considered, X, in the expression F(X) can
have either the meaning X1 or X2, and F can have any of the meanings F1, F2,
or F3. All six possible combinations of meanings must be considered in
resolving the overloading. Given the parameter and result type profile for
F1, F2, and F3, we can see that F(X) can be given only the following
interpretations: F1(X1), F2(X2), or F3(X2). Since a unique interpretation is
therefore not possible, the type conversion is ambiguous.