'gfortran compiler error calling recursive log_gamma function

I uploaded a 2F1 hypergeometric function but it turns out that it does not compile on my computer. It is from this article. I use

GNU Fortran (Built by Jeroen for the R-project) 8.3.0

shiped with RTools 4.0. Can you figure out why it does not compile and how this could be solved? In the code below, I just kept the one line that generates the error. The error is given next.

MODULE HYP_2F1_MODULE
  !--------------------------------------------------------------------
  IMPLICIT NONE
  INTEGER, PARAMETER :: PR=KIND(1.0D0)
  REAL(PR)     ::  ONE=1.0D0
CONTAINS
  !
END MODULE HYP_2F1_MODULE
!
!----------------------------------------------------------------------
RECURSIVE FUNCTION LOG_GAMMA(Z) RESULT(RES)

  USE HYP_2F1_MODULE
  IMPLICIT NONE
  COMPLEX(PR),INTENT(IN) :: Z
  COMPLEX(PR)  :: RES
  !
     RES = LOG_GAMMA( ONE -z);
  !
END FUNCTION LOG_GAMMA

Here is the error message

 testZ.f90:18:22:

      RES = LOG_GAMMA( ONE - Z);
                 1
Error: 'x' argument of 'log_gamma' intrinsic at (1) must be REAL


Solution 1:[1]

There is a Fortran 2008+ intrinsic of the same name

16.9.119 LOG_GAMMA (X)
1 Description. Logarithm of the absolute value of the gamma function.
2 Class. Elemental function.
3 Argument. X shall be of type real. Its value shall not be a negative integer or zero.

There is some sort of clash I do not completely understand here. The obvious workaround is to rename your function. What I can say is that without the result clause (which you need because of the recursive attribute) the intrinsic would be shadowed. It might be a compiler bug.

Also consider, whether the intrinsic of the same name couldn't also do what you need from your function.

Solution 2:[2]

In addition to @VladimirF's suggestions, you can add the compiler flag -std=f95 to enforce compliance with the Fortran 95 standard. Provided you haven't added -fall-intrinsics this will disable all intrinsics from standards after Fortran 95, and should make the legacy code work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 veryreverie