Nvfortran fails to accept `target` argument to `pointer` dummy argument when in generic interface

module mymod
  implicit none

  interface in_generic 
    module procedure with_ptr
  end interface


contains

    subroutine with_ptr(a)
        real, pointer, intent(in) :: a(:)     
    end subroutine

end module mymod


program main 
    use mymod, only : in_generic, with_ptr

    implicit none 

    real, target :: a(20)
    integer :: i

    a = [( real(i) , i = 1, size(a))]

    ! Does not compile
    call in_generic(a)

    ! Compiles with no issue 
    call with_ptr(a)
  

end program main

Also here Compiler Explorer

In the code snippet above, which I believe is a valid Fortran 2008, the generic interface does not apply correctly and does not accept an argument with a target attribute when provided to a dummy argument with pointer attribute. It only happens when the procedure is inside a generic interface.

As demonstrated above everything works if the procedure is applied directly.

I believe it is acompiler bug. Or am I missing something?

I have tried to search the forum for any prior filing, but couldn’t find it. I hope it is not a duplicate, if it is I apologise.

Hi mak60 and welcome!

I was able to reproduce the issue here and filed a report with engineering, TPR #39134.

While I’m not sure, but think this is a F2008 feature where the standard was relaxed to allow a TARGET array to match a POINTER argument in a generic interface. The current PGI based nvfortran only partially supports F2008 so this may be more a feature request rather than a bug report.

Note that I did try our upcoming LLVM based nvfortran, which fully supports F2018, and the code compiles as expected.

-Mat

Hi!

Thanks for opening the ticket and quick reply! Will look forward to monitoring how it develops : )

While I’m not sure, but think this is a F2008 feature where the standard was relaxed to allow a TARGET array to match a POINTER argument in a generic interface. The current PGI based nvfortran only partially supports F2008 so this may be more a feature request rather than a bug report.

I was also initially thinking that it might be unsupported F2008 feature, but the fact that the target actual argument is accepted by a subroutine with dummy pointer argument when called outside the generic interface convinced me it is probably intended to be supported.

Basically the problem is that in the example above calling with_ptr directly compiles and works. Only in_generic call fails to compile : )