Expected behavior of type-bound operators

Expected behavior of type-bound operators


If I compile the following code with ifort 14.0.3

module abmod
  implicit none

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

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

  subroutine a_assign(this, value)
    implicit none
    class(a), intent(out) :: this
    integer, intent(in) :: value
    print *, "I am a_assign!"
  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!"
  end subroutine b_assign

end module abmod

program test
  use abmod
  implicit none

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


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

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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.

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)

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today