在内部类型上重载 Fortran 内部运算符?

Overload Fortran intrinsic operator on intrinsic types?

求代码

module pow_mod
implicit none
integer, parameter :: dp = kind(1.0d0)
interface operator(**)
   module procedure mypow
end interface
contains
!
function mypow(x,y) result(x_to_y)
real(kind=dp), intent(in) :: x,y
real(kind=dp)             :: x_to_y
x_to_y = exp(y*log(x))
end function mypow
end module pow_mod

gfortran 说

pow_fast.f90:5:25:

    5 |    module procedure mypow
      |                         1
Error: Operator interface at (1) conflicts with intrinsic interface

Intel Fortran 也有类似的说法。 Fortran 中是否可以在内部类型上重载内部运算符?

Fortran 2018 中的此限制禁止这样做

15.4.3.4.2
Defined operations 1 If OPERATOR is specified in a generic specification, all of the procedures specified in the generic interface shall be functions that may be referenced as defined operations (10.1.6, 15.5). In the case of functions of two arguments, infix binary operator notation is implied. In the case of functions of one argument, prefix operator notation is implied. OPERATOR shall not be specified for functions with no arguments or for functions with more than two arguments. The dummy arguments shall be nonoptional dummy data objects and shall have the INTENT (IN) or VALUE attribute. The function result shall not have assumed character length. If the operator is an intrinsic-operator (R608), the number of dummy arguments shall be consistent with the intrinsic uses of that operator, and the types, kind type parameters, or ranks of the dummy arguments shall differ from those required for the intrinsic operation (10.1.5).

不允许定义这样的操作。来自 Fortran 2018 (15.4.3.4.2):

If the operator is an intrinsic-operator (R608), the number of dummy arguments shall be consistent with the intrinsic uses of that operator, and the types, kind type parameters, or ranks of the dummy arguments shall differ from those required for the intrinsic operation (10.1.5).