On Tuesday, November 8, 2022 at 12:16:33 PM UTC-5, Peter Klausler US wrote:
> Generic interfaces are constrained in some specific circumstances to contain all functions or all subroutines, but in general they can contain both. (There's language in the standard that pertains to the visibility of intrinsic procedures of the same name that depends on whether a generic interface contains a mixture or not, so it must be possible.)
>
Re: "but in general they can contain both," from what I can understand from 18-007r1 document toward Fortran 2018, I do *not* think the semantics of the standard is such that "in general they can contain both" Sure the standard has following carve out but that does suggest any generality, in fact the section on "Restrictions on generic declarations" indicates the opposite:
"Within the scope of a generic name that is the same as the generic name of an intrinsic procedure, the intrinsic procedure is not accessible by its generic name if the procedures in the interface and the intrinsic procedure are *not all functions or not all subroutines*. If a generic invocation is consistent with both a specific procedure from an interface and an accessible intrinsic procedure, it is the specific procedure from the interface that is referenced."
(emphasis with asterisk is mine)
> While it's probably not the best practice to explicitly define an interface that has a mixture of functions and subroutines, it's possible for such an interface to be created -- perhaps inadvertently -- when an interface is defined in multiple locations and merged together. For example:
>
I think the intended message by the OP with example is misleading. The example is *not* "explicitly define an interface that has a mixture of functions and subroutines, it's possible for such an interface to be created -- perhaps inadvertently -- when an interface is defined in multiple locations and merged together"
Rather the example shows two different ultimate entities, both of which are generic interfaces named 'generic'. One ultimate entity is that for functions (func being one specific procedure in it) and the other for subroutines (subr being one specific procedure in this interface).
I think the standard only permits the second of these two entities to be referenced in the scope containing the USE statement, meaning the following:
A) consume the generic as a function, here note the order of USE statements
program main
use m2
use m1
print *, generic(42)
end
Or
B) consume the generic as a subroutine, note the order of USE statements is opposite to that A)
program main
use m1
use m2
call generic
end
It will take me effort to decode the standardese and try to explain in plain English but I think this is tied to semantics with "An ultimate entity is a module entity that is not accessed by use association. An accessed entity shall not be associated with two or more ultimate entities unless its identifier is not used, or the ultimate entities are generic interfaces. Generic interfaces are handled as described in 15.4.3.4."
I think this is also tied to how the standard permits extension of generic interfaces via USE statements, as in the following example:
module m1
interface generic
module procedure func
end interface
contains
integer function func(n)
integer, intent(in) :: n
func = n
end function
end module
module m2
interface generic
module procedure func
end interface
contains
real function func(n)
real, intent(in) :: n
func = n
end function
end module
program main
use m1
use m2
print *, generic(42)
print *, generic(99.0)
end
>.. So I think I'm going to get to add another item to f18's documentation section on features that it supports that are standard but might as well not be.
Honestly I think the "f18 documentation" on "features that it supports that are standard but might as well not be" needs a thorough review by a subgroup in the J3 committee, say JoR or /DATA or the Editor. I think there are inaccuracies in that "f18 documentation", the above comments by OP in the original post on generic interfaces will be one such if that were to get included. Until the f18 team (is it all at Nvidia?) can get it thoroughly reviewed and all corrections applied, ideally it will only be in the publicly available online with clearly stated disclaimers.