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

Unexpected compiler error with the use of a type-bound procedure returning a POINTER type in the intrinsic function ASSOCIATED

FortranFan
Honored Contributor II
327 Views

The compiler error with the following code appears to be incorrect:

module m

   implicit none

   private

   type, public :: t
      private
      integer, pointer :: m_i
   contains
      private
      procedure, pass(this), public :: iptr => getptr
      procedure, pass(this), public :: setptr
   end type t


contains

   subroutine setptr( this, iptr )

      !.. Argument list
      class(t), intent(inout)         :: this
      integer, pointer, intent(inout) :: iptr

      this%m_i => iptr

      return

   end subroutine setptr

   function getptr( this ) result( iptr )

      !.. Argument list
      class(t), intent(in) :: this
      !.. Function result
      integer, pointer :: iptr

      iptr => this%m_i

      return

   end function getptr

end module m
program p

   use m, only : t

   integer, pointer :: i
   type(t) :: foo

   print *, " Is i associated with foo%iptr? ", associated( i, foo%iptr() )

   stop

end program p
Compiling with Intel(R) Visual Fortran Compiler XE 15.0.4.221 [Intel(R) 64]...
p.f90
C:\..\p.f90(8): error #6808: The TARGET argument must have the POINTER or TARGET attribute.
[ASSOCIATED]
compilation aborted for C:\..\p.f90 (code 1)

 

0 Kudos
6 Replies
FortranFan
Honored Contributor II
327 Views

FWIW, Compiler 15.0, update 2 gives the same error as well.

0 Kudos
FortranFan
Honored Contributor II
327 Views

And just to show it is a problem with the type-bound aspect of the type, code compiles and works ok with the following simple change:

module m

   implicit none

   private

   type, public :: t
      private
      integer, pointer :: m_i
   contains
      private
      procedure, pass(this), public :: iptr => getptr
      procedure, pass(this), public :: setptr
   end type t

   public :: getptr

contains

   subroutine setptr( this, iptr )

      !.. Argument list
      class(t), intent(inout)         :: this
      integer, pointer, intent(inout) :: iptr

      this%m_i => iptr

      return

   end subroutine setptr

   function getptr( this ) result( iptr )

      !.. Argument list
      class(t), intent(in) :: this
      !.. Function result
      integer, pointer :: iptr

      iptr => this%m_i

      return

   end function getptr

end module m
program p

   use m, only : t, getptr

   integer, pointer :: i
   type(t) :: foo

   !.. create i with some value
   allocate(i, source=42)

   call foo%setptr( i )

   print *, " Is i associated with getptr( foo )? ", associated( i, getptr( foo ) )
   print *, " getptr( foo ) = ", getptr( foo )
   print *, " foo%iptr() = ", foo%iptr()

   stop

end program p

Upon execution,

  Is i associated with getptr( foo)?  T
  getptr( foo ) =  42
  foo%iptr() =  42
Press any key to continue . . .

 

0 Kudos
Kevin_D_Intel
Employee
327 Views

Thank you FortranFan for all the details. I reported this to our Developers and will keep you updated about what I hear back.

(Internal tracking id: DPD200374298)

(Resolution Update on 02/27/2016): This defect is fixed in the Intel® Parallel Studio XE 2016 Update 2 Release (PSXE 2016.2.055/ CnL 2016.2.180 - Windows)

0 Kudos
FortranFan
Honored Contributor II
327 Views

Thanks, Kevin, for your prompt follow-up.

0 Kudos
Kevin_D_Intel
Employee
327 Views

The erroneous error noted in post #1 is fixed in the latest PSXE 2016 Update 2 release (PSXE 2016.2.055/ CnL 2016.2.180 - Windows)

0 Kudos
FortranFan
Honored Contributor II
327 Views

Kevin Davis (Intel) wrote:

The erroneous error noted in post #1 is fixed in the latest PSXE 2016 Update 2 release (PSXE 2016.2.055/ CnL 2016.2.180 - Windows)

Thanks, Kevn, for the update - I've confirmed the fix.

0 Kudos
Reply