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

associated() not working with type-bound procedure pointer

AAK
Novice
568 Views

Hi,

I get an error when trying to check the association status of a procedure pointer, that is a member of a derived type. When the procedure pointer is not declared inside a derived type, there is no error.

TL;DR

associated(mytype%ptr, target=func1) ! error #6423
associated(ptr, target=func1) ! no error

 

Here is a MWE of the working version:

module routines
implicit none

  abstract interface 
    real function if() result(y)
    implicit none
    end function
  end interface

contains
  
  ! def two functions with interface `if`
  real function func1() result(y)
  implicit none
    y=1.
  end function
  real function func2() result(y)
  implicit none
    y=2.
  end function 
end module routines


program main
use routines
implicit none
procedure(if), pointer :: ptr
print *, 'set ptr to func1'
ptr => func1
print *, 'is ptr associated with func1', associated(ptr, target=func1)
print *, 'is ptr associated with func2', associated(ptr, target=func1)
print *, 'call ptr', ptr()
end program 

 

The following code

module m_routines
implicit none

  abstract interface 
    real function if() result(y)
    implicit none
    end function
  end interface

  type wrap_ptr
    procedure(if), nopass, pointer  ::  ptr => null()
  end type

contains 

  subroutine m_routines_select_ptr(this, i)
  implicit none
  class(wrap_ptr), intent(inout) ::  this
  integer, intent(in) ::  i
    if(i==1) this%ptr => func1
    if(i==2) this%ptr => func2
  end subroutine

  ! def two functions with interface `if`
  real function func1() result(y)
  implicit none
    y=1.
  end function
  real function func2() result(y)
  implicit none
    y=2.
  end function 
end module m_routines


program main
use m_routines
implicit none
type(wrap_ptr) foo
print *, 'set ptr to func1'
foo%ptr => func1
print *, 'is ptr associated with func1', associated(foo%ptr, target=func1)  ! error #6423
print *, 'is ptr associated with func2', associated(foo%ptr, target=func2)  ! error #6423
print *, 'call ptr', foo%ptr()
end program 

compiles with this error

assoc_in_type.f90(42): error #6423: This name has already been used as an external function name.   [FUNC1]
print *, 'is ptr associated with func1', associated(foo%ptr, target=func1)
--------------------------------------------------------------------^

using ifort, but compiles well with gfortran.

 

My newest available version of ifort is  `19.1.2.254 20200623`.
My gfortran version is `gcc version 7.5.0 (SUSE Linux)`

The only reference I found was a comment of @SteveLionel here.

 

Is this a compiler bug or a subtlety of the standard?

0 Kudos
2 Replies
Steve_Lionel
Honored Contributor III
548 Views

Looks like a bug to me. The standard says, for ASSOCIATED: "TARGET (optional) shall be allowable as the data-target or proc-target in a pointer assignment statement (10.2.2) in which POINTER is data-pointer-object or proc-pointer-object. If TARGET is a pointer then its pointer association status shall not be undefined."

Clearly foo%ptr is "allowable as a proc-target in a pointer assignment statement" - indeed, you did that on the previous line. I know of no reason why a pointer component would be disallowed but a pointer variable allowed.

0 Kudos
FortranFan
Honored Contributor II
531 Views

@AAK ,

For whatever it's worth, your code looks conformant to me.  Submitting a support request at Intel OSC or expecting Intel staff to pick it from here makes sense.

0 Kudos
Reply