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

Expected behavior of type-bound operators

Emil_S_
Beginner
459 Views

Hi

If I compile the following code with ifort 14.0.3

module abmod
  implicit none

  type :: a
     integer :: value
   contains
     procedure :: assign => a_assign
     generic :: assignment(=) => assign
  end type a

  type, extends(a) :: b
   contains
     procedure :: assign => b_assign
  end type b

contains
  subroutine a_assign(this, value)
    implicit none
    class(a), intent(out) :: this
    integer, intent(in) :: value
    print *, "I am a_assign!"
    this%value=value
  end subroutine a_assign
    
  subroutine b_assign(this, value)
    implicit none
    class(b), intent(out) :: this
    integer, intent(in) :: value
    print *, "I am b_assign!"
    this%value=value
  end subroutine b_assign

end module abmod

program test
  use abmod
  implicit none

  class(a), allocatable :: aclass
  class(b), allocatable :: bclass

  allocate(b::aclass)
  allocate(bclass)

  aclass=1
  bclass=1
end program test

And run the program, I get

$ ifort -g -o test test.f90

$ ./test

I am a_assign!

I am a_assign!

$

Is this the expected behavior? I had expected that the b_assign procedure would have been called in both cases, due to the dynamic type being class b. I see similar behavior with the other operators.

If I use gfortran 4.6, 4.7 or 4.9, the b_assign procedure is called. However gfortran 4.8 shows similar behavior as ifort 14.0.3

Best regards

Emil Sørensen

0 Kudos
3 Replies
Izaak_Beekman
New Contributor II
459 Views

This behavior from ifort doesn’t make sense to me, I would expect assign_b to be called as well. Haven’t had time to dig through the standard yet, however.

0 Kudos
Kevin_D_Intel
Employee
459 Views

I also see the same reported behavior with our current Beta. I reported this to Development (see internal tracking id below) to get their assessment and will keep you updated on what I hear.

(Internal tracking id: DPD200358171)

(Resolution Update on 09/12/2015): This defect is fixed in the Intel® Parallel Studio XE 2016 Release (2016.0.109 - Linux)

0 Kudos
Kevin_D_Intel
Employee
459 Views

I confirmed the associated fix for this issue in the Intel® Parallel Studio XE 2016 Release (Version 16.0.0.109 Build 20150815) available from the Intel® Software Development Products Registration Center (IRC).

0 Kudos
Reply