J3/04-343
Date: 16 June 2004
To: J3
From: Andy Vaught
Subject: Interface conflict detection
NUMBER:
TITLE: Detection of ambiguous interfaces
KEYWORDS: interfaces, ambiguous
DEFECT TYPE: ??
STATUS: J3 consideration in progress
Consider the following fragment which is modified from a recent
post to comp.lang.fortran:
interface i
subroutine pf_init_2d(nx,ny,fac,name,nph)
integer, intent(out) :: nx,ny
integer, intent(in) :: fac
character(*), intent(in) :: name
integer, intent(in), optional :: nph
end subroutine pf_init_2d
subroutine pf_init_3d(nx,ny,nz,fac,name,nph)
integer, intent(out) :: nx,ny,nz
integer, intent(in) :: fac
character(*), intent(in) :: name
integer, intent(in), optional :: nph
end interface
By the rules in section 16.2.3, these unambiguous interfaces are
classified as ambiguous.
The optional arguments prevent the argument-counting rule from
distinguishing the interfaces. The pf_init_2d interface does
not have a disambiguating dummy argument name from pf_init_3d,
so pf_init_3d must satisfy rule 3.
Considering the interface for pf_init_3d, the argument that
disambiguates by position is the fourth argument, 'fac', while the
argument that disambiguates by keyword is the third argument, 'nz'.
Since the positional argument occurs later, the final clause of
rule 3 is not satisfied and the interfaces are classified as ambiguous.
The correct test is that the argument that disambiguates by name
must be the same as or follow the argument that disambiguates by TKR.
If an actual argument list has enough positional arguments to get
to the positionally disambiguating argument, all is well. Otherwise,
there must be keywords arguments prior to this and they have to
disambiguate the interface.
EDITS:
410:13 Change "earlier" to "later".
SUBMITTED BY: Andy Vaught
HISTORY: