j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
178 stars 15 forks source link

15.4.3.4.5 and C.11.6 are incomplete, needless, and largely unimplemented; delete them #327

Open klausler opened 10 months ago

klausler commented 10 months ago

Fortran has rules (15.4.3.4.5) that apply to each pair of specific procedures in a generic procedure interface. They are intended to ensure at the time of declaration (or merging via USE association) that every possible reference to that generic procedure can be unambiguously resolved to exactly one of its specific procedures.

These rules are incomplete, and the related note in C.11.6 admits as much. It is possible to write a generic interface that is unambiguous by inspection, yet still non-conformant to these rules.

Further, the goal of defining rules to prevent ambiguity in every possible reference is overkill. What is perhaps needed is only an assurance that it is possible to invoke each of the specific procedures unambiguously. Or, which nearly every compiler is doing anyway, it suffices to simply check each actual reference to a generic procedure to ensure that it resolves to exactly one of its specific procedures.

These rules appear not to have been implemented in gfortran, the Intel compilers, nvfortran, or in NAG. XLF has them, and as a result is unable to compile the unit test framework pFUnit. f18 had them, but I'm reducing them to portability warnings only, so that unambiguous existing applications can be compiled.

Example highly reduced from pFUnit:

module m
  interface generic
    procedure sub1, sub2
  end interface
 contains
  subroutine sub1(b, c)
    class(*) b
    integer, optional :: c
  end
  subroutine sub2(a, b, c)
    real a
    class(*) b
    integer, optional :: c
  end
end

The call generic(1.,2) would be ambiguous, but never happens.