Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28455 Discussions

Pure procedure pointers in parameterized derived types

Stephan_S
Beginner
847 Views

 

The following code does not compile with ifort Version 2021.4.0:

module my_mod
implicit none
type my_type(rkind)
integer, kind :: rkind
real(kind=rkind) :: val
procedure(sqrt_sub), pointer, nopass :: sub => NULL()
end type my_type

contains

pure subroutine bla_my_type_8(m_in,m_out)
implicit none
type(my_type(8)), intent(out) :: m_out
type(my_type(8)), intent(in) :: m_in
m_out%val = 2*m_in%val
m_out%sub => m_in%sub
end subroutine bla_my_type_8

pure subroutine sqrt_sub(x, y)
implicit none
real(kind=8), intent(in) :: x
real(kind=8), intent(out) :: y
y = sqrt(x)
end subroutine sqrt_sub

end module my_mod

program my_prog
use my_mod
implicit none
type(my_type(8)) :: m
real(kind=8) :: x, y

x = 16
m%sub => sqrt_sub
call m%sub(x, y)
write(*,*) 'y =', y

end program my_prog

Trying to compile results in the following error messages:

prog.f90(17): error #7137: Any procedure referenced in a PURE procedure, including one referenced via a defined operation or assignment, must have an explicit interface and be declared PURE.   [SUB]

    m_out%sub => m_in%sub

----------^

prog.f90(17): error #7137: Any procedure referenced in a PURE procedure, including one referenced via a defined operation or assignment, must have an explicit interface and be declared PURE.   [SUB]

    m_out%sub => m_in%sub

----------------------^

compilation aborted for prog.f90 (code 1)

 

The issue is probably related to this one I posted two days ago: 

https://community.intel.com/t5/Intel-Fortran-Compiler/Procedure-pointer-in-parameterized-derived-type/td-p/1328783

However, I am not really sure if this is really the case. I know that procedure targets must not be elemental, non-intrinsic procedures, but I am not aware of any restrictions with respect to pure procedures. Can anyone clarify?

 

0 Kudos
3 Replies
FortranFan
Honored Contributor II
820 Views

@Stephan_S ,

 

Again I can vouch your code conforms to the standard (barring a nit with your use of hard-wired value of 8 for REAL kind that a standard-conforming processor can legitimately refuse to recognize).

I believe Intel Fortran compiler is wrong otherwise in issuing those errors.  The same feedback I provided in your earlier thread that you link in your original post applies here i.e., in terms of follow-up with Intel Fortran team.

All the best with speedy resolution of your issues with Intel,

0 Kudos
Stephan_S
Beginner
811 Views

@FortranFan ,

Thanks again for the quick reply! I only used real(kind=8) here to keep the example compact. Hopefully Intel will pick up the problem from here at some point. In theory, the university I work for has premier support, but so far, I have not managed to get access. Still trying though... 

0 Kudos
FortranFan
Honored Contributor II
771 Views

@Stephan_S , something like the following can be a starting point for compactness with your issue, with enough effort, you can try to condense it further:

   type t(k)
      integer, kind :: k
      procedure(asub), pointer, nopass :: sub
   end type
contains
   pure subroutine s( r, l )
      type(t(k=1)), intent(out) :: l
      type(t(k=1)), intent(in)  :: r
      l%sub => r%sub
   end subroutine
   pure subroutine asub()
   end subroutine
end

 

C:\Temp>ifort /c /standard-semantics p.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.3.0 Build 20210609_000000
Copyright (C) 1985-2021 Intel Corporation.  All rights reserved.

p.f90(9): error #7137: Any procedure referenced in a PURE procedure, including one referenced via a defined operation or assignment, must have an explicit interface and be declared PURE.   [SUB]
      l%sub => r%sub
--------^
p.f90(9): error #7137: Any procedure referenced in a PURE procedure, including one referenced via a defined operation or assignment, must have an explicit interface and be declared PURE.   [SUB]
      l%sub => r%sub
-----------------^
compilation aborted for p.f90 (code 1)

 

0 Kudos
Reply